summaryrefslogtreecommitdiff
path: root/platform/darwin
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-03-27 22:40:15 -0700
committerMinh Nguyễn <mxn@1ec5.org>2016-03-29 11:46:27 -0700
commit8c8b0580388460c0addafb49c852ea8986b47ac4 (patch)
tree2e55e038689eba4d0faf71c251adca8543ea8075 /platform/darwin
parentaff1196d02cd06e71c7b2a15454384fd302946b1 (diff)
downloadqtlocation-mapboxgl-8c8b0580388460c0addafb49c852ea8986b47ac4.tar.gz
[ios, osx] Include progress in progress change notification
An MGLOfflinePackProgressChangedNotification notification now includes the pack’s state and progress values, which match the values in the corresponding MGLOfflinePack properties. Implemented NSValue category methods to store MGLOfflinePackProgress inside a dictionary.
Diffstat (limited to 'platform/darwin')
-rw-r--r--platform/darwin/include/MGLOfflinePack.h21
-rw-r--r--platform/darwin/include/MGLOfflineStorage.h35
-rw-r--r--platform/darwin/src/MGLOfflinePack.mm14
-rw-r--r--platform/darwin/src/MGLOfflineStorage.mm7
4 files changed, 70 insertions, 7 deletions
diff --git a/platform/darwin/include/MGLOfflinePack.h b/platform/darwin/include/MGLOfflinePack.h
index 185bba038c..b65fed3849 100644
--- a/platform/darwin/include/MGLOfflinePack.h
+++ b/platform/darwin/include/MGLOfflinePack.h
@@ -161,4 +161,25 @@ typedef struct MGLOfflinePackProgress {
@end
+/**
+ Methods for round-tripping `MGLOfflinePackProgress` values.
+ */
+@interface NSValue (MGLOfflinePackAdditions)
+
+/**
+ Creates a new value object containing the given `MGLOfflinePackProgress`
+ structure.
+
+ @param progress The value for the new object.
+ @return A new value object that contains the offline pack progress information.
+ */
++ (NSValue *)valueWithMGLOfflinePackProgress:(MGLOfflinePackProgress)progress;
+
+/**
+ The `MGLOfflinePackProgress` structure representation of the value.
+ */
+@property (readonly) MGLOfflinePackProgress MGLOfflinePackProgressValue;
+
+@end
+
NS_ASSUME_NONNULL_END
diff --git a/platform/darwin/include/MGLOfflineStorage.h b/platform/darwin/include/MGLOfflineStorage.h
index f9ddba0382..5544663d3e 100644
--- a/platform/darwin/include/MGLOfflineStorage.h
+++ b/platform/darwin/include/MGLOfflineStorage.h
@@ -14,8 +14,11 @@ NS_ASSUME_NONNULL_BEGIN
resources are required for offline viewing. This notification is posted
whenever any field in the `progress` property changes.
- The `object` is the `MGLOfflinePack` object whose progress changed. For details
- about the pack’s current progress, use the pack’s `progress` property.
+ The `object` is the `MGLOfflinePack` object whose progress changed. The
+ `userInfo` dictionary contains the pack’s current state in the
+ `MGLOfflinePackStateUserInfoKey` key and details about the pack’s current
+ progress in the `MGLOfflinePackProgressUserInfoKey` key. You may also consult
+ the pack’s `state` and `progress` properties, which provide the same values.
If you only need to observe changes in a particular pack’s progress, you can
alternatively observe KVO change notifications to the pack’s `progress` key
@@ -52,17 +55,37 @@ extern NSString * const MGLOfflinePackErrorNotification;
extern NSString * const MGLOfflinePackMaximumMapboxTilesReachedNotification;
/**
+ The key for an `NSNumber` object that indicates an offline pack’s current
+ state. This key is used in the `userInfo` dictionary of an
+ `MGLOfflinePackProgressChangedNotification` notification. Call `-integerValue`
+ on the object to receive the `MGLOfflinePackState`-typed state.
+ */
+extern NSString * const MGLOfflinePackStateUserInfoKey;
+
+/**
+ The key for an `NSValue` object that indicates an offline pack’s current
+ progress. This key is used in the `userInfo` dictionary of an
+ `MGLOfflinePackProgressChangedNotification` notification. Call
+ `-MGLOfflinePackProgressValue` on the object to receive the
+ `MGLOfflinePackProgress`-typed progress.
+ */
+extern NSString * const MGLOfflinePackProgressUserInfoKey;
+
+/**
The key for an `NSError` object that is encountered in the course of
- downloading an offline pack. The error’s domain is `MGLErrorDomain`. See
- `MGLErrorCode` for possible error codes.
+ downloading an offline pack. This key is used in the `userInfo` dictionary of
+ an `MGLOfflinePackErrorNotification` notification. The error’s domain is
+ `MGLErrorDomain`. See `MGLErrorCode` for possible error codes.
*/
extern NSString * const MGLOfflinePackErrorUserInfoKey;
/**
The key for an `NSNumber` object that indicates the maximum number of
Mapbox-hosted tiles that may be downloaded and stored on the current device.
- Call `-unsignedLongLongValue` on the object to receive the `uint64_t`-typed
- tile limit.
+ This key is used in the `userInfo` dictionary of an
+ `MGLOfflinePackMaximumMapboxTilesReachedNotification` notification. Call
+ `-unsignedLongLongValue` on the object to receive the `uint64_t`-typed tile
+ limit.
*/
extern NSString * const MGLOfflinePackMaximumCountUserInfoKey;
diff --git a/platform/darwin/src/MGLOfflinePack.mm b/platform/darwin/src/MGLOfflinePack.mm
index 30b268aaf1..05ff35ec7f 100644
--- a/platform/darwin/src/MGLOfflinePack.mm
+++ b/platform/darwin/src/MGLOfflinePack.mm
@@ -204,3 +204,17 @@ void MBGLOfflineRegionObserver::mapboxTileCountLimitExceeded(uint64_t limit) {
[pack.delegate offlinePack:pack didReceiveMaximumAllowedMapboxTiles:limit];
});
}
+
+@implementation NSValue (MGLOfflinePackAdditions)
+
++ (NSValue *)valueWithMGLOfflinePackProgress:(MGLOfflinePackProgress)progress {
+ return [NSValue value:&progress withObjCType:@encode(MGLOfflinePackProgress)];
+}
+
+- (MGLOfflinePackProgress)MGLOfflinePackProgressValue {
+ MGLOfflinePackProgress progress;
+ [self getValue:&progress];
+ return progress;
+}
+
+@end
diff --git a/platform/darwin/src/MGLOfflineStorage.mm b/platform/darwin/src/MGLOfflineStorage.mm
index 619e4ce1ab..3d171ca203 100644
--- a/platform/darwin/src/MGLOfflineStorage.mm
+++ b/platform/darwin/src/MGLOfflineStorage.mm
@@ -15,6 +15,8 @@ NSString * const MGLOfflinePackProgressChangedNotification = @"MGLOfflinePackPro
NSString * const MGLOfflinePackErrorNotification = @"MGLOfflinePackError";
NSString * const MGLOfflinePackMaximumMapboxTilesReachedNotification = @"MGLOfflinePackMaximumMapboxTilesReached";
+NSString * const MGLOfflinePackStateUserInfoKey = @"State";
+NSString * const MGLOfflinePackProgressUserInfoKey = @"Progress";
NSString * const MGLOfflinePackErrorUserInfoKey = @"Error";
NSString * const MGLOfflinePackMaximumCountUserInfoKey = @"MaximumCount";
@@ -242,7 +244,10 @@ NSString * const MGLOfflinePackMaximumCountUserInfoKey = @"MaximumCount";
#pragma mark MGLOfflinePackDelegate methods
- (void)offlinePack:(MGLOfflinePack *)pack progressDidChange:(__unused MGLOfflinePackProgress)progress {
- [[NSNotificationCenter defaultCenter] postNotificationName:MGLOfflinePackProgressChangedNotification object:pack];
+ [[NSNotificationCenter defaultCenter] postNotificationName:MGLOfflinePackProgressChangedNotification object:pack userInfo:@{
+ MGLOfflinePackStateUserInfoKey: @(pack.state),
+ MGLOfflinePackProgressUserInfoKey: [NSValue valueWithMGLOfflinePackProgress:progress],
+ }];
}
- (void)offlinePack:(MGLOfflinePack *)pack didReceiveError:(NSError *)error {