Cannot find file AFJSONRequestOperation.h with AFNetworking and AFOAuth2Client

I use cocoapods to install AFNetworking and AFOAuth2Client. The problem is that it cannot import the AFJSONREquestOperation header file. I have no idea where this dependency is. Is this another module or extension for AFNetworking?

+6
source share
4 answers

It depends on the version of AFNetworking 2.x you have installed, but AFOAuth2 uses version 1.x (latest version 1.x 1.3.3)

If you used Cocoapods, just write in the pod pod file 'AFNetworking', '1.3.3' and run "pod install"

+3
source

@ The correct answer is correct - at the moment, AFOAuth2Client is not compatible with AFNetworking 2.0. There is an open pull request https://github.com/AFNetworking/AFOAuth2Client/pull/55 , which should make AFOAuth2Client work with AFNetworking 2.0.

You could unlock the mlwelles repo or use https://github.com/mlwelles/AFOAuth2Client.git by changing your subtype for the AFOAuth2Client line to look like this:

pod 'AFOAuth2Client', :git => 'git://github.com/mlwelles/AFOAuth2Client.git' 
+3
source

Try importing it as follows:

 #import <AFNetworking/AFJSONRequestOperation.h> 

If you cannot do this, make sure you are using Xcode 5. What happened to me when using Xcode 4.6.3.

+1
source

AFHTTPRequestOperationManager based on code

AFNetworking 2.x

 AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; [manager GET:@"http://example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; 

AFNetworking 3.x

 AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; [manager GET:@"http://example.com/resources.json" parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) { NSLog(@"JSON: %@", responseObject); } failure:^(NSURLSessionTask *operation, NSError *error) { NSLog(@"Error: %@", error); }]; 

AFHTTPRequestOperation Based Code

AFNetworking 2.x

 NSURL *URL = [NSURL URLWithString:@"http://example.com/resources/123.json"]; NSURLRequest *request = [NSURLRequest requestWithURL:URL]; AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request]; op.responseSerializer = [AFJSONResponseSerializer serializer]; [op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; [[NSOperationQueue mainQueue] addOperation:op]; 

AFNetworking 3.x

 NSURL *URL = [NSURL URLWithString:@"http://example.com/resources/123.json"]; AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; [manager GET:URL.absoluteString parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) { NSLog(@"JSON: %@", responseObject); } failure:^(NSURLSessionTask *operation, NSError *error) { NSLog(@"Error: %@", error); }]; 

This answer is useful for users who use AFNetworking 2.x and 3.x Thank you.

0
source

Source: https://habr.com/ru/post/956970/


All Articles