0

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.

enfix
  • 6,188
  • 11
  • 51
  • 75

2 Answers2

1

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:

David Berry
  • 40,337
  • 12
  • 82
  • 94
0

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.

Community
  • 1
  • 1
Holly
  • 5,200
  • 1
  • 23
  • 27