Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[iOS] Offline download from background thread #14206

Closed
Etienne-io opened this issue Mar 22, 2019 · 5 comments
Closed

[iOS] Offline download from background thread #14206

Etienne-io opened this issue Mar 22, 2019 · 5 comments
Labels
archived Archived because of inactivity iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS

Comments

@Etienne-io
Copy link

I was working on an application that requires offline download. I have to perform an Api call before starting to download the map and the callback of this call is not running on the main thread.

I ran the download process from this background thread and the download works fine. But, when I instantiate the map, it crashes.

iOS Version 4.9.0 (tested on 4.7.0 and 4.8.0)

Steps to reproduce

  1. Before instantiating the map, call MWZOfflineStorage.shared on a background thread
  2. Instantiate the map

Expected behavior

The map should be displayed

Actual behavior

The application crash

Opinions

  • I didn't find any information about the fact that MWZOfflineStorage.shared should be instantiated on the main thread. If I missed this information, sorry for this post.

  • As MWZOfflineStorage.shared is a Singleton, I suppose that when the first call is made in a background thread the MGLMapView fails to use it properly in the main thread.

Etienne

@tobrun tobrun added the iOS Mapbox Maps SDK for iOS label Mar 27, 2019
@1ec5 1ec5 added the macOS Mapbox Maps SDK for macOS label Apr 3, 2019
@1ec5
Copy link
Contributor

1ec5 commented Apr 3, 2019

Would it be feasible for your application to interact with the singleton within a dispatch_async block on the main queue?

MGLOfflineStorage wasn’t designed to be initialized on a background thread, at least. I’m not sure how feasible it would be to make the class safe for background threads, given all the work it does on the file system with the cache database and, as you mention, its use by MGLMapView and potentially other UI classes.

We should probably document that MGLOfflineStorage.sharedOfflineStorage needs to run on the main thread. Note that MGLOfflineStorageDelegate’s methods are also called on the main thread.

@stale stale bot added the archived Archived because of inactivity label Sep 30, 2019
@stale
Copy link

stale bot commented Sep 30, 2019

This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

@stale stale bot closed this as completed Sep 30, 2019
@julianrex julianrex reopened this Sep 30, 2019
@stale stale bot removed the archived Archived because of inactivity label Sep 30, 2019
@Etienne-io
Copy link
Author

Hi,

Sorry for the lake of reactivity, I didn't see your response to this issue.
This issue was mostly to let you know this behavior and the missing information in the documentation about it.

Note: If I remember properly, we can instantiate from the background thread, run a region download and it works fine. The crash occurs only when you try to display the map after that.

Etienne

@stale stale bot added the archived Archived because of inactivity label Mar 29, 2020
@stale
Copy link

stale bot commented Mar 29, 2020

This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

@stale stale bot closed this as completed Mar 29, 2020
@goors
Copy link

goors commented Jun 30, 2023

It would be great if this can work on DispatchQueue.global().async {}. That is not possible right?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived Archived because of inactivity iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS
Projects
None yet
Development

No branches or pull requests

5 participants