Skip to content

Instantly share code, notes, and snippets.

@vigneshr89
Last active November 1, 2022 06:06
Show Gist options
  • Save vigneshr89/c35e324632f10f636780 to your computer and use it in GitHub Desktop.
Save vigneshr89/c35e324632f10f636780 to your computer and use it in GitHub Desktop.
NSURLSession Background service steps
For a background download service with NSURLSession
1. Create a download task with background session configuration with NSURLSession delegates.
2. If, application is in foreground NSURLsession delegate will be called directly.
3. If application is background or killed additional methods are needed in the app delegate .
4. "handleEventsForBackgroundURLSession" will be called first, where it is necessary to reinstate the session object with the delegate again. Otherwise delegate methods will not be called.
5. "URLSessionDidFinishEventsForBackgroundURLSession" will be called once everything is done. You can decide what you want to do once the download is complete like updating the UI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment