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

2

18

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.

Fennell answered 23/11, 2013 at 6:42 Comment(0)
F
21

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.

Fennell answered 3/12, 2013 at 17:4 Comment(0)
F
5

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.

Fib answered 3/9, 2015 at 21:27 Comment(1)
This is very important and helpful - yet your link to the "docs" is just to the main entry-point of Apple UIKit docs - which leaves the reader to try dig and find relevant information. If you found the relevant passage in the docs - could you be so kind as to update the link to be more direct?Cherokee

© 2022 - 2024 — McMap. All rights reserved.