Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: Does force quitting the app disables background upload using NSURLSession?

The question is around NSURLSession and NSURLSessionUploadTask.

I'm uploading large files to server and noticed that when I force quit the app the whole background upload just stops. However, when upload starts while app is running through the Xcode/debugger, then my upload completes just fine even when I stop the app running via Xcode 'stop' button. I suspect that force quitting the app using Xcode simulates an iOS system command and not a user action.

So my question is whether it's true that iOS would immediately cancel NSURLSessionUploadTask when user force quit the app?? For some reason I would at least expect an error callback to the app, however nothing happens.

like image 737
ymotov Avatar asked Nov 23 '13 06:11

ymotov


2 Answers

I can confirm now after a bunch of testing that background task will run ok if the app is just put into background. However, if user force quit the app manually, then iOS cancels all scheduled background tasks. So next time the app is launched I'm getting all the callbacks to the delegate with the error code of a canceled task.

Hope it helps someone looking into the same thing.

like image 160
ymotov Avatar answered Oct 19 '22 08:10

ymotov


From Apple's docs about background execution:

If tasks have not yet finished and the system terminates your app, the system automatically continues managing the tasks in the background. If the user terminates your app, the system cancels any pending tasks.

like image 36
mannannlegur Avatar answered Oct 19 '22 10:10

mannannlegur