Here's something you should consider (taken from this StackOverflow question):
AFHTTPRequestOperationManager
uses the old NSURLConnection
so that
doesn't facilitate background downloading.
AFURLSessionManager
uses NSURLSession
under the hood so that does
That being said, if for some reason you insist on using the AFHTTPRequestOperationManager
keep on reading.
If you are trying to run this code in applicationDidEnterBackground:
or similar then it's understandable why you're not seeing anything in the console. When the application enters the background it can be put in a suspended state by the OS at any time which is probably what is happening in your case (read more about App States). If you need more time to run code then you must explicitly ask for it by calling:
__block UIBackgroundTaskIdentifier backgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{}
This should be placed just before the code you wish to run in the background.
The expiration handler is called once your app has run out of time and is going to be suspended. It is important to finish up whatever you were doing (in your case you should cancel the GET request if it has not completed) and call:
[application endBackgroundTask:backgroundTaskIdentifier]
All in all your code should look something like this:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
__block AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
__block UIBackgroundTaskIdentifier backgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
[manager.operationQueue cancelAllOperations];
[[UIApplication sharedApplication] endBackgroundTask:backgroundTaskIdentifier];
}];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager GET:@"SOMEURLHIDDEN" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"%@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%@",error);
}];
}