How to keep iOS code running when in background

Hi,


we are doing an application that needs to potentialy transfer a lot of files from a server to an iPad before it goes offline. So we are using the NSUrlSession do to background transfer with a periodic background fetch to enqueue the files to downloads when we didn't succeed to enqueue all of them when our application was in foreground (or to download new files). The BeginBackgroundTask helps us get more times, but it's far from being infinite.


The issues we encountered with this implementation is the background transfer is not made to transfer too much files at the same time (the nsurlsessiond process ends-up with 100%+ CPU usage which will crash from times to times because of ">50% CPU over 180s", and after queueing too much requests, sometime the API calls to queue new background downloads will blocks, even on iOS 9.1, and even after unintalling our application).


But when we tested other apps doing file transfer for offline usage, we noticed some other apps can successfully transfert 6000+ files in background without any issue, eg.: Box (https://itunes.apple.com/ca/app/box-for-iphone-and-ipad/id290853822). When we profile it using apple Instruments Activity monitor, we notice the Box process can run for 20+ minutes without being killed with "Application didn't leave it in time" as it usually happens when you don't stop you code from executing before the backgroundTimeRemaining reach 0 (the % CPU column never reach 0%).


So the question: any idea how Box managed to keep their own code running past the usual backgroundTimeRemaining limitation?


Thanks!

we are doing an application that needs to potentialy transfer a lot of files from a server to an iPad before it goes offline.

Your best option here is to reduce the number of individual resources you are transferring. Moving to Fewer, Larger Transfers has a bunch of suggestions on this front.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I know it's better to do less downloads, but it's not always easy as it has lots of implication.


So my question is not how I could do less queries as it's what we want to avoid, but rather on how Box did succeed to keep their own process running where other apps get kills because the backgroundTimeRemaining reach 0.

So my question is […] how Box did succeed to keep their own process running where other apps get kills because the backgroundTimeRemaining reach 0.

I’m not in a position to reverse engineer other developer’s app on your behalf.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I'm not asking to reverse engineer. It's just a fact that other apps succeed to run their app in background for longer than what the OS usually allow.


So what I'm interested on is what is the way of doing it, as there is clearly a way of doing it as we can prove by looking at the Box process while its syncing files in background.

There’s no magic bullet here. The supported ways to run continuously in the background are all governed by the UIBackgroundModes information property list key.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
How to keep iOS code running when in background
 
 
Q