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

Update for AFNetworking 2.0.1 #8

Open

Description

@walsht

Please update code to support AFNetworking 2.0.1

Activity

  1. alexkotenko commented on Oct 17, 2013

    @alexkotenko

    Hi
    Please update code AFNetworking 2.0.1.

  2. uzman commented on Jan 17, 2014

    @uzman

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

    }

  3. ijameelkhan commented on Jun 2, 2015

    @ijameelkhan

    I fixed it in #14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions