If I have a large file download going on an the app gets moved to background, is there any way to keep the download executing functions alive?
I knowbeginBackgroundTaskWithExpirationHandler: gets called when the app moves to the background and I can start my task there, but I don’t want to start a new task, I want to complete my old task. It can be solved with beginBackgroundTaskWithExpirationHandler:, but for that I need to pause my download and resume it from the right place, which is just plain silly.
Ideally what I want is that I wrap my download function with an expiration handler, so my download function keeps executing for the permitted time after the app has been moved to the background.
This is exactly how it works.
beginBackgroundTaskWithExpirationHandler:is not called when you enter the background. It’s what you call to indicate that you’re starting something that, if you happen to go into the background while it’s running, you would like to finish. Just wrap your existing download code withbeginBackgroundTaskWithExpirationHandler:andendBackgroundTask:.