diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2016-03-25 17:02:08 -0700 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2016-03-29 11:46:25 -0700 |
commit | a1e5701fa3fa7041cbbdd3edabd1c6a8006ce68b (patch) | |
tree | 4ad07a8c03277f4f9d4700ad27fd351ded166139 /platform/darwin/include | |
parent | bbab5a5b5e9b3cd2461a1c088f8610e6f1938686 (diff) | |
download | qtlocation-mapboxgl-a1e5701fa3fa7041cbbdd3edabd1c6a8006ce68b.tar.gz |
[ios, osx] Centralized offline pack management
MGLOfflineStorage now maintains a centralized, strongly held, KVO-compliant collection of all extant offline packs. MGLOfflineStorage issues notifications for progress updates. Client code can now react to the successful addition of an offline pack either via the completion block or via a KVO insertion.
Fixes #4287.
Diffstat (limited to 'platform/darwin/include')
-rw-r--r-- | platform/darwin/include/MGLOfflinePack.h | 10 | ||||
-rw-r--r-- | platform/darwin/include/MGLOfflineStorage.h | 36 |
2 files changed, 17 insertions, 29 deletions
diff --git a/platform/darwin/include/MGLOfflinePack.h b/platform/darwin/include/MGLOfflinePack.h index d1f5a3ed53..fd8080523c 100644 --- a/platform/darwin/include/MGLOfflinePack.h +++ b/platform/darwin/include/MGLOfflinePack.h @@ -148,16 +148,6 @@ typedef struct MGLOfflinePackProgress { */ - (void)suspend; -/** - Request an asynchronous update to the pack’s `state` and `progress` properties. - - The state and progress of an inactive or completed pack are computed lazily. If - you need the state or progress of a pack inside an - `MGLOfflinePackListingCompletionHandler`, set the `delegate` property then call - this method. - */ -- (void)requestProgress; - @end /** diff --git a/platform/darwin/include/MGLOfflineStorage.h b/platform/darwin/include/MGLOfflineStorage.h index 4f3432163b..931982dce3 100644 --- a/platform/darwin/include/MGLOfflineStorage.h +++ b/platform/darwin/include/MGLOfflineStorage.h @@ -7,6 +7,13 @@ NS_ASSUME_NONNULL_BEGIN @class MGLOfflinePack; @protocol MGLOfflineRegion; +extern NSString * const MGLOfflinePackProgressChangedNotification; +extern NSString * const MGLOfflinePackErrorNotification; +extern NSString * const MGLOfflinePackMaximumMapboxTilesReachedNotification; + +extern NSString * const MGLOfflinePackErrorUserInfoKey; +extern NSString * const MGLOfflinePackMaximumCountUserInfoKey; + /** A block to be called once an offline pack has been completely created and added. @@ -29,16 +36,6 @@ typedef void (^MGLOfflinePackAdditionCompletionHandler)(MGLOfflinePack * _Nullab typedef void (^MGLOfflinePackRemovalCompletionHandler)(NSError * _Nullable error); /** - A block to be called with a complete list of offline packs. - - @param pack Contains a pointer an array of packs, or `nil` if there was an - error obtaining the packs. - @param error Contains a pointer to an error object (if any) indicating why the - list of packs could not be obtained. - */ -typedef void (^MGLOfflinePackListingCompletionHandler)(NS_ARRAY_OF(MGLOfflinePack *) *packs, NSError * _Nullable error); - -/** 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. @@ -50,7 +47,16 @@ typedef void (^MGLOfflinePackListingCompletionHandler)(NS_ARRAY_OF(MGLOfflinePac */ + (instancetype)sharedOfflineStorage; -- (instancetype)init NS_UNAVAILABLE; +/** + An array of all known offline packs. + + This property is set to `nil`, indicating that the receiver does not yet know + the existing packs, for an undefined amount of time starting from the moment + the shared offline storage object is initialized until the packs are fetched + from the database. After that point, this property is always non-nil, but it + may be empty to indicate that no packs are present. + */ +@property (nonatomic, copy, readonly, nullable) NS_ARRAY_OF(MGLOfflinePack *) *packs; /** Creates and registers an offline pack that downloads the resources needed to @@ -85,14 +91,6 @@ typedef void (^MGLOfflinePackListingCompletionHandler)(NS_ARRAY_OF(MGLOfflinePac - (void)removePack:(MGLOfflinePack *)pack withCompletionHandler:(nullable MGLOfflinePackRemovalCompletionHandler)completion; /** - Asynchronously calls a completion callback with all existing offline packs. - - @param completion The completion handler to call with the list of packs. This - handler is executed asynchronously on the main queue. - */ -- (void)getPacksWithCompletionHandler:(MGLOfflinePackListingCompletionHandler)completion; - -/** Sets the maximum number of Mapbox-hosted tiles that may be downloaded and stored on the current device. |