-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Support background transfers on iOS #4291
Comments
I'm for using platform specific networking when possible because, as @1ec5 noted, there are some pretty big advantages for mobile scenarios (at least on iOS). |
This was a huge limitation with |
In a sense, mbgl is using platform-specific networking, in that it’s all NSURL code under the hood. But mbgl itself abstracts away the difference between this networking code and the Android-specific networking code. I haven’t looked closely, but I think the primary difficulty will be plumbing through mbgl to the NSURL code when data is received in the background. |
Does background transfer require a monolithic download of a single URL? Offline downloads don't fit into that paradigm. |
I think it would support multiple URLs. Background transfers work through NSURLSession, which we’re already using, and a single NSURLSession supports multiple NSURLSessionDataTasks. We’d configure the session to accept background data. When it arrives, if the application has been killed (as opposed to suspended), the application is relaunched and |
|
When I resume a paused download, I do think the battery savings and reliability of background transfers would be valuable enough to warrant some additional complexity, but I’m not familiar enough with the offline storage design in mbgl to make a call on that. In the meantime, as a workaround, MGLOfflineStorage – or indeed the application code itself – could begin a background task for the duration of the download. |
Hi, does anyone have an example of how to download the offline maps using an NSURLSession? If this example could show how to download > 1 map in a loop or queue that would be eveb better. Apologies if this is fairly obvious to most but i'm reasonably new to obj-c in general. My app needs to download 6 offline maps, which i can do, but i need it to happen in the background in case the user doesn't keep the screen alive while this happens as this caused a crash during testing. The only way i know how to use NSURLSession would be to set up some data tasks and then supply a url but the only way i know how to start an offline map download is to create a pack and call resume on it. Therefore, i have no URL to give the NSURLSession to run the download job??? |
An alternative of course would be to run each map download as a finite length background task in a loop but that provides no guarantee that you will be given enough time for the map download to complete |
@Craigelcocoa The UIKit background task API does not provide enough time to complete an offline map download. The best you can do when app enters background is to create a background task that pauses any active map downloads and then resume those downloads when the app subsequently activates. The only way for offline map downloads to truly work in the background is for the Mapbox-iOS-SDK to implement downloads using |
Hi thanks for the reply, much appreciated. Hopefully, NSURLSessionDownloadTask will be added to the mapbox sdk in the near future |
any way to achieve this in the current version? |
+1 |
I hope that MGLOfflinePack will be able to caching in the background. |
Is there any progress in this thread? |
This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions. |
1 similar comment
This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions. |
Though the offline pack sideloading mechanism does mitigate this issue somewhat, end users still expect to be able to switch applications or lock the screen while an application downloads offline packs, and developers don’t intuitively expect to have to keep the screen alive. |
I fully agree with @1ec5 ! This limitation is quite annoying for users. Is there any progress yet? |
MGLOfflineStorage and associated APIs require the application to be open in order for the download to proceed to completion. Alternatively, the application can explicitly take power assertions to keep the application running in the background without being suspended or suddenly terminated. However, for large offline packs, even power assertions aren’t a great solution, because they require the entire application to run, impacting battery life.
iOS and OS X support background transfers, which allow the download to continue in a separate process while the application is suspended or terminated. ForeverMap 2 makes use of this feature, and it’s a decent experience on an iPad. The background transfer feature on iOS requires us to cede total control of the download to NSURLSession. Is that even feasible with the architecture we’ve created for offline downloads in mbgl?
/cc @jfirebaugh @boundsj
The text was updated successfully, but these errors were encountered: