Skip to content
This repository has been archived by the owner on Mar 22, 2019. It is now read-only.

Update for AFNetworking 2.0.1 #8

Open
walsht opened this issue Oct 14, 2013 · 3 comments
Open

Update for AFNetworking 2.0.1 #8

walsht opened this issue Oct 14, 2013 · 3 comments

Comments

@walsht
Copy link

walsht commented Oct 14, 2013

Please update code to support AFNetworking 2.0.1

@alexkotenko
Copy link

Hi
Please update code AFNetworking 2.0.1.

@uzman
Copy link

uzman commented Jan 17, 2014

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

}

@ijameelkhan
Copy link

I fixed it in #14

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants