What is the proper use case for NSURLSessions background sessions?
Asked Answered
S

1

3

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?

Semiconductor answered 20/7, 2017 at 15:48 Comment(0)
S
-1

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.

Semiconductor answered 25/7, 2017 at 16:16 Comment(3)
The question is when should we use beginBackgroundTaskWithExpirationHandler vs Background Session, and you are juxtaposing background work (which applies to both options in the question) vs "force the user to wait until the end and reach to a definitive completion of either a success or failure" for very specific casesStatistics
I was trying to communicated that if for your app it's better to force the user to wait then it's better to not use Background Session. Is that wrong? Also I'd enjoy if you can write an answer, since no body answered, I just wrote my own best answer ¯_(ツ)_/¯Semiconductor
What you are saying is correct, but it is irrelevant when the question is in regards to choosing between two non-forcing-await background solutions. I might write an answer when I am done with my research in this regard, and have done several experimentsStatistics

© 2022 - 2024 — McMap. All rights reserved.