OpenWeatherMapAPI icon indicating copy to clipboard operation
OpenWeatherMapAPI copied to clipboard

Update for AFNetworking 2.0.1

Open walsht opened this issue 11 years ago • 3 comments

Please update code to support AFNetworking 2.0.1

walsht avatar Oct 14 '13 15:10 walsht

Hi Please update code AFNetworking 2.0.1.

alexkotenko avatar Oct 17 '13 07:10 alexkotenko

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];

}

uzman avatar Jan 17 '14 22:01 uzman

I fixed it in #14

ijameelkhan avatar Jun 02 '15 12:06 ijameelkhan