I want to upload an image, using AFnetworking, which I have done successfully, now I want that to be uploaded even if it the app is in background execution , Is that possible?
I have tried this code:
- (void)applicationWillResignActive:(UIApplication *)application {
UIBackgroundTaskIdentifier backgroundIdentifier = [application beginBackgroundTaskWithExpirationHandler:^(void) {
[[AFHTTPClient sharedClient] cancelAllHTTPOperations]; }]; [application endBackgroundTask:backgroundIdentifier];
}
But it is showing error on shared-client selector and cancelallHTTPoperations method that they are undefined.
Any help will be greatly appreciated.
When an app goes to background, the iOS will decide whether or not to completely stop your app or give it some time to complete what it's doing.
In case it wants your app to stop, the expiration handler is called.
If that's happening you should suspend all your tasks as fast as possible and prepare for a complete kill of the app, because that is what will happen a very short time after (5 seconds max). Take a look here.
Hope this helps you.