1
votes

I am wanting to add offline map functionality to an iOS app build using Swift and Mapbox. There is great documentation and examples for downloading a map region pack, but am having a difficult time figuring out how to retrieve a list of offline packs. Their documentation here gives these instructions on how to receive:

"To detect when the shared offline storage object has finished loading its packs property, observe KVO change notifications on the packs key path. The initial load results in an NSKeyValueChangeSetting change."

But I am having a difficult time find any examples or explanations as to what that means. Any help would be greatly appreciated!

2

2 Answers

1
votes

An array of all known offline packs can be retrieved using the .packs attribute of the MGLOfflineStorage class. Like so:

MGLOfflineStorage.shared.packs

To access these packs, you just need to iterate over the array or pass a specific index and retrieve whatever information you're interested in from the packs.

There is a good example of using this array to create a tableview of the completed offline packs on a device in the SDK's open source test app (NB: this example is written in Obj-C).


⚠️ Disclaimer: I currently work at Mabpox ⚠️

0
votes

I was finally able to come to a solution. To observe the packs retrieval using Swift, you can use this code:

MGLOfflineStorage.shared.observe(\.packs, options: [.new, .old]){ object, change in
    var offlinePacksArr : [MGLOfflinePack] = object.packs // Access to packs array here
}