Reputation: 6164
in My iPhone App I want to integrate Yelp API
for that I download Yelp example from GitHub
I tried to Add All library files ,both Frameworks for Yelp and Github into my project
but still I am not able to reference the files which are in framework"s Header.
like:GHAsyncTestCase and it is giving message can not find interface declaration "GHAsyncTestCase" superClass of AOuthTest
What could be wrong ?
please help me to integrate it and if possible explain me all required steps to integrate it into my project.
Thanks
Upvotes: 2
Views: 3336
Reputation: 19418
you have do additional settin in xcode
YAJL Framework Installing in XCode 4 (iOS)
* 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
you can create custom class or write the below code in any class but i suggest you to create custom class as follows :
in .h file say 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
now in test.m
file
#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
I hope it help. Its working for me ....
Upvotes: 6