1
votes

I'm learning to use AFNetworking and do a GET request.

AFNetworking (3.1.0)

XCode 6

Code:

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager GET:@"http://localhost:5000/index" parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) {
        NSLog(@"JSON: %@", responseObject);
    } failure:^(NSURLSessionTask *operation, NSError *error) {
        NSLog(@"Error: %@", error)p;
    }];

However, I got the error

Incompatible block pointer types sending 'void (^)(NSURLSessionTask *__strong, NSError *__strong)' to parameter of type 'void (^ __nullable)(NSURLSessionDataTask * __nonnull __strong)'

Tried many times but couldn't figure out why?

2
Look at the failure block. What are the parameters supposed to be? What are you using? See the difference? The error is showing the difference. They are similar but different.rmaddy
What if I want to get the html page? What should the parameters be?jinglei
Just now I checked the document. Doesn't Xcode 6 support AFNetworking 3.0+?jinglei

2 Answers

2
votes

Finally I find out that the problem really is the wrong version Xcode. In Xcode 6 it doesn't recognize nullable. Upgrading my Xcode just solved the problem.

0
votes

i think your parameter value don't send nil values, I am also using afNetworking Get method, please refer below code,

viewDidLoad give below code:

NSURL *url = [NSURL URLWithString:@"http://localhost:5000/index"];

    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    //AFNetworking asynchronous url request
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

        movies = [responseObject objectForKey:@"enquiry"];

        NSSortDescriptor *titleSort = [[NSSortDescriptor alloc] initWithKey:@"FirstName"
                                                                  ascending:YES selector:@selector(caseInsensitiveCompare:)];
//        NSMutableArray *sortDescriptors = [[NSMutableArray alloc] initWithObjects: titleSort, nil];
        movies=[NSMutableArray arrayWithArray:[movies sortedArrayUsingDescriptors:@[titleSort]]];

        NSLog(@"The Array: %@",movies);
        [self.mytableView reloadData];

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

        NSLog(@"Request Failed: %@, %@", error, error.userInfo);

    }];

    [operation start];

don't forget #import "AFNetworking.h" in header hope its helpful