enfix
enfix

Reputation: 6960

Make NSURLConnection async when app goes bakcground

I need to do a simple NSURLConnection when application goes in background or when ends.
How can I do this ?
I dont' need to download anything or to do any long time operations, I only need to call an API from web service.

Upvotes: 0

Views: 45

Answers (2)

Holly
Holly

Reputation: 5290

If you can only need iOS 7 as a deployment target, you can use the background task API introduced in iOS 7. You can see it in action in this post.

Upvotes: 0

David Berry
David Berry

Reputation: 41226

In your applicationWillResignActive use -[UIApplication beginBackgroundTaskWithExpirationHandler:] to start up a background network operation. Be sure to call endBackgroundTask when you're done. The major caution here is that you only have a short amount of time (10 seconds iirc) to finish up.

https://developer.apple.com/library/ios/documentation/uikit/reference/UIApplication_Class/Reference/Reference.html#//apple_ref/occ/instm/UIApplication/beginBackgroundTaskWithExpirationHandler:

Upvotes: 1

Related Questions