Reputation: 893
I wish to send a little data (location Co-ordinates) to my server from the application which is running in background in iOS 7. I am using NSURLSessions for this purpose.
I am confused regarding the type of session I should use for this purpose :
Default Session: Can we create and use default sessions in background. If yes can it handle the network failures gracefully.
Background Session: Can I upload data as NSData object using background session.
PS: Some code will be really appreciated dealing with network failure in both cases.
Upvotes: 6
Views: 4624
Reputation: 498
I would advise you to use Background session.
You may use Default session or a regular NSURLConnection with a background expiry identifier with a max of 10 minutes to complete your tasks
Background Task Identifier Documentation
Using NSURLConnection in background task ( you also get iOS 6 support)
NSURLConnection best practise when enter background
By the new standards you can use Background Session to handle downloads/ server uploads.
Apple's documentation on handling background downloads
A Simple project from Apple illustrating the technique
Hope this helps you !
Upvotes: 7