himanth himanth - 11 months ago 191
Objective-C Question

dataTaskWithRequest:completionHandler: is deprecated

I'm using

in my project to get the data from REST api.
But when I'm using the method which described in Github I'm getting warning.

Here is my code :

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];

NSURL *URL = [NSURL URLWithString:@"http://httpbin.org/get"];
NSURLRequest *request123 = [NSURLRequest requestWithURL:URL];

NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request123 completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
if (error) {
NSLog(@"Error: %@", error);
} else {
NSLog(@"%@ %@", response, responseObject);

[dataTask resume];

My project supports iOS 7.0 and above.

My Xcode version 7.3.1

Is there any way to overcome this warning?

Answer Source

This method belongs to AFURLSessionManager. The actual signature (using two blocks) is

- (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request 
                                      success:(void ( ^ ) ( NSURLResponse *response , id responseObject ))success 
                                      failure:(void ( ^ ) ( NSError *error ))failure