1

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.

4

1 回答 1

1

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.

于 2014-03-21T04:58:28.373 回答