gpt4 book ai didi

iPhone应用程序 : Yelp Api integration problem

转载 作者:行者123 更新时间:2023-12-03 20:28:32 24 4
gpt4 key购买 nike

在我的 iPhone 应用程序中我想集成 Yelp API

为此,我从 GitHub 下载 Yelp 示例

我尝试将所有库文件(包括 Yelp 和 Github 框架)添加到我的项目中

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

像:GHAsyncTestCase,它给出消息找不到接口(interface)声明“GHAsyncTestCase”AOuthTest的父类(super class)

可能出了什么问题?

请帮助我集成它,如果可能的话,请向我解释将其集成到我的项目中所需的所有步骤。

谢谢

最佳答案

你必须在 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

希望对您有帮助。它对我有用......

关于iPhone应用程序 : Yelp Api integration problem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6857252/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com