OpenWeatherMapAPI
OpenWeatherMapAPI copied to clipboard
Update for AFNetworking 2.0.1
Please update code to support AFNetworking 2.0.1
Hi Please update code AFNetworking 2.0.1.
hi, please do below.
-download the AFNetwroking latest version. -put the AFNetwrking dir to your project -add the necessary framework to your project
- in OWMWeatherAPI.m class: add; //#import "AFJSONRequestOperation.h" --> delete this #import "AFHTTPRequestOperation.h"
here is the updated method:
-
(void) callMethod:(NSString ) method withCallback:( void (^)( NSError error, NSDictionary *result ) )callback {
NSOperationQueue *callerQueue = [NSOperationQueue currentQueue];
// build the lang paramter NSString *langString; if (_lang && _lang.length > 0) { langString = [NSString stringWithFormat:@"&lang=%@", _lang]; } else { langString = @""; }
NSString *urlString = [NSString stringWithFormat:@"%@%@%@&APPID=%@%@", _baseURL, _apiVersion, method, _apiKey, langString];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
/* AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
// callback on the caller queue NSDictionary *res = [self convertResult:JSON]; [callerQueue addOperationWithBlock:^{ callback(nil, res); }];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
// callback on the caller queue [callerQueue addOperationWithBlock:^{ callback(error, nil); }];
}]; [_weatherQueue addOperation:operation]; */
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; operation.responseSerializer = [AFJSONResponseSerializer serializer]; [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
// callback on the caller queue NSDictionary *res = [self convertResult:responseObject]; [callerQueue addOperationWithBlock:^{ callback(nil, res); }];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { //NSLog(@"error: %@", operation.responseString); [callerQueue addOperationWithBlock:^{ callback(error, nil); }];
}]; [_weatherQueue addOperation:operation];
}
I fixed it in #14