繁体   English   中英

iPhone App:Yelp Api集成问题

[英]iPhone App: Yelp Api integration problem

在我的iPhone App中,我想集成Yelp API

为此,我从GitHub下载Yelp示例

我试图将Yelp和Github的所有库文件都添加到我的项目中

但我仍然无法引用框架标题中的文件。

like:GHAsyncTestCase,它给消息找不到AOuthTest的接口声明“ GHAsyncTestCase”超类

有什么问题吗?

请帮助我将其集成,并在可能的情况下向我解释将其集成到我的项目中的所有必要步骤。

谢谢

你在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>.

EDITED

您可以创建自定义类或在任何类中编写以下代码,但我建议您按以下方式创建自定义类:

在.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

希望对您有所帮助。 它为我工作....

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM