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,680
  • 12
  • 55
  • 80

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,941
  • 12
  • 84
  • 95
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,270
  • 1
  • 24
  • 27