在我的 iPhone 应用程序中,我想集成 Yelp API
为此,我从 GitHub 下载 Yelp 示例
我尝试将 Yelp 和 Github 的所有库文件添加到我的项目中
但我仍然无法引用框架标题中的文件。
喜欢:GHAsyncTestCase,它给出消息找不到接口声明“GHAsyncTestCase”AOuthTest 的超类
有什么问题?
请帮我整合它,如果可能的话,向我解释将它整合到我的项目中所需的所有步骤。
谢谢
在我的 iPhone 应用程序中,我想集成 Yelp API
为此,我从 GitHub 下载 Yelp 示例
我尝试将 Yelp 和 Github 的所有库文件添加到我的项目中
但我仍然无法引用框架标题中的文件。
喜欢:GHAsyncTestCase,它给出消息找不到接口声明“GHAsyncTestCase”AOuthTest 的超类
有什么问题?
请帮我整合它,如果可能的话,向我解释将它整合到我的项目中所需的所有步骤。
谢谢
你在 xcode 中做了额外的设置
在 XCode 4 (iOS) 中安装 YAJL 框架
* In Build Phases, make sure its listed in Link Binary With Libraries, along with:
o CoreGraphics.framework
o Foundation.framework
o UIKit.framework
* In Build Settings:
o Under Framework Search Paths make sure the (parent) directory to YAJLiOS.framework is listed.
o Under Other Linker Flags in your target, add -ObjC and -all_load
* Import with #import <YAJL/YAJL.h>.
已编辑
您可以创建自定义类或在任何类中编写以下代码,但我建议您按如下方式创建自定义类:
在 .h 文件中说test.h
#import <Foundation/Foundation.h>
#import "OAuthConsumer.h"
#import <GHUnit/GHUnit.h>
#import <YAJL/YAJL.h>
@interface test : NSObject
{
NSMutableData *responseData;
NSDictionary *JSON1 ;
}
- (NSMutableDictionary *) getData ;
@end
现在在test.m
文件中
#import "test.h"
#import "OAuthConsumer.h"
@implementation test
- (void)test:(NSString *)urlString
{
NSURL *URL = [NSURL URLWithString:@"http://api.yelp.com/v2/search?term=restaurants&location=new%20york"];
OAConsumer *consumer = [[[OAConsumer alloc] initWithKey:@"yourKey" secret:@"yourKey"] autorelease];
OAToken *token = [[[OAToken alloc] initWithKey:@"yourKey-" secret:@"yourKey-Bc"] autorelease];
id<OASignatureProviding, NSObject> provider = [[[OAHMAC_SHA1SignatureProvider alloc] init] autorelease];
NSString *realm = nil;
OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:URL
consumer:consumer
token:token
realm:realm
signatureProvider:provider];
[request prepare];
responseData = [[NSMutableData alloc] init];
//[self prepare];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
//[self waitForStatus:kGHUnitWaitStatusSuccess timeout:10.0];
//NSDictionary *JSON = [responseData yajl_JSON];
//GHTestLog(@"JSON: %@", [JSON yajl_JSONStringWithOptions:YAJLGenOptionsBeautify indentString:@" "]);
//NSLog(@"%@",[JSON valueForKey:@"region"]);
[connection release];
[request release];
}
- (void) setString
{
//NSMutableString *JSON = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
//NSLog(@"JSON Data Parsing:--->%@",JSON);
JSON1 = [responseData yajl_JSON];
NSArray *arry = [JSON1 valueForKey:@"businesses"];
for (int i = 0; i < [arry count]; i ++)
{
NSLog(@"Res Name : %@",[[arry objectAtIndex:i] valueForKey:@"name"]);
}
NSDictionary *temp = [arry objectAtIndex:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[responseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"Error: %@, %@", [error localizedDescription], [error localizedFailureReason]);
//[self notify:kGHUnitWaitStatusFailure forSelector:@selector(test)];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[self setString];
//[self notify:kGHUnitWaitStatusSuccess forSelector:@selector(test)];
}
- (NSDictionary *) getData
{
return JSON1 ;
}
- (void)tearDown
{
[responseData release];
responseData = nil;
}
@end
我希望它有所帮助。它为我工作....