MGLOfflineStorage

@interface MGLOfflineStorage : NSObject

MGLOfflineStorage implements a singleton (shared object) that manages offline packs. All of this class’s instance methods are asynchronous, reflecting the fact that offline resources are stored in a database.

  • Returns the shared offline storage object.

    Declaration

    Objective-C

    + (nonnull instancetype)sharedOfflineStorage;
  • Creates and registers an offline pack that downloads the resources needed to use the given region offline.

    The resulting pack starts out with a state of MGLOfflinePackStateInactive. To begin downloading resources, call -[MGLOfflinePack resume]. To monitor download progress, set the pack’s delegate property to an object that conforms to the MGLOfflinePackDelegate protocol.

    Declaration

    Objective-C

    - (void)addPackForRegion:(nonnull id<MGLOfflineRegion>)region
                 withContext:(nonnull NSData *)context
           completionHandler:
               (nullable MGLOfflinePackAdditionCompletionHandler)completion;

    Parameters

    region

    A region to download.

    context

    Arbitrary data to store alongside the downloaded resources.

    completion

    The completion handler to call once the pack has been added. This handler is executed asynchronously on the main queue.

  • Unregisters the given offline pack and frees any resources that are no longer required by any remaining packs.

    As soon as this method is called on a pack, the pack becomes invalid; any attempt to send it a message will result in an exception being thrown. If an error occurs and the pack cannot be removed, do not attempt to reuse the pack object. Instead, use the -getPacksWithCompletionHandler: method to obtain a valid pointer to the pack object.

    Declaration

    Objective-C

    - (void)removePack:(nonnull MGLOfflinePack *)pack
        withCompletionHandler:
            (nullable MGLOfflinePackRemovalCompletionHandler)completion;

    Parameters

    pack

    The offline pack to remove.

    completion

    The completion handler to call once the pack has been removed. This handler is executed asynchronously on the main queue.

  • Asynchronously calls a completion callback with all existing offline packs.

    Declaration

    Objective-C

    - (void)getPacksWithCompletionHandler:
            (nonnull MGLOfflinePackListingCompletionHandler)completion;

    Parameters

    completion

    The completion handler to call with the list of packs. This handler is executed asynchronously on the main queue.

  • Sets the maximum number of Mapbox-hosted tiles that may be downloaded and stored on the current device.

    Once this limit is reached, -[MGLOfflinePackDelegate offlinePack:didReceiveMaximumAllowedMapboxTiles:] is called on every delegate of MGLOfflinePack until already downloaded tiles are removed by calling the -removePack:withCompletionHandler: method.

    Note

    The Mapbox Terms of Service prohibits changing or bypassing this limit without permission from Mapbox. Contact your Mapbox sales representative to have the limit raised.

    Declaration

    Objective-C

    - (void)setMaximumAllowedMapboxTiles:(uint64_t)maximumCount;