What is the proper use case for NSURLSessions background sessions?
In the comments of this answer I was having a discussion about backgroundTasks which eventually led to:
Use backgroundTasks for anything that isn’t related to download/upload. For upload/download use NSURLSessions’s backgroundSessions. Then I made another comment asking why not use background Sessions for all types of requests and was told:
For regular REST calls, background sessions are much less convenient,
and generally not what you’d want. They’re not a general purpose tool
for every request; they’re for performing uploads and downloads.
What makes background sessions less convenient for REST calls? Sometimes you may have slow internet with a huge chunk of data. Wouldn’t it be a convenience to make sure all your data submissions go through?
- iOS/Cocoa - NSURLSession - Handling Basic HTTPS Authorization
- POST request with a simple string in body with Alamofire
- Uploading an image from iOS to PHP
- HTTP “Content-Disposition: attachment” and downloading files on iOS web browser
- waitUntilAllTasksAreFinished error Swift
- sending a post from iOS app to php script not working… Simple solution is likey
Solutions Collect From Internet About “What is the proper use case for NSURLSessions background sessions?”
I’m not sure but if you’re doing something like a bank transaction, you wouldn’t want to use a backgroundSession. Because you want the user to know of the decision before they leave. User should never the assumption that they could leave app and app would continue to work as should. Nor they should be under the impression that they can resume (by a downloadTaskWithUrl).
What happens if for some reason the user makes a $2000 transaction and hits the button expecting the transaction to go through but it doesn’t. The next time the user comes back to the screen they could either be logged out due to security reasons and never know about it or stay logged in but they see an alert that the transaction failed. And now they’re like “Oh no my daughter needed $2000 urgently. She must be still waiting for the money!”.
You don’t want to allow users to have bad expectations*. Rather you want users to take FULL responsibility themselves and not hit home screen and wait for the success/failure. So once the user clicks on submit transfer he’d wait for it to either get success and move on or see failure and wait and investigate the reason his transaction didn’t go through.
You usually convey the possibility of failure through an spinner/animation and the actual outcome (failure or success) through an alert.
*Bad expectation is: Every time I hit the the submit transfer button it will go through and there’s 0 chance of failure and no need for you to wait and see it go through.
- iOS Simulator interface blurry in Xcode 6 GM iOS 8
- Only having one view autorotate in xcode?
- Add codesign to private key ACL without Keychain
- Free hand drawing in google maps-iOS
- Convert Swift Array to Dictionary with indexes
- Weird colors in XCode Interface Builder?
- How to set-up In App Purchase free trial period in iOS app
- XCTest Unit Test data response not set in test after viewDidLoad
- iOS set MKMapView camera heading rotation around anchor point
- Specific compiler flags for specific files in Xcode
- Animating the presenting view in a UIPresentationController
- ios uitextfield like notes
- Keyboard and cursor show, but I can't type inside UITextFields and UITextViews
- How do I automatically activate an item in the OS X Services Menu