summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLOfflinePack.mm
diff options
context:
space:
mode:
authorEimantas Vaiciunas <eimantas@walkingsmarts.com>2017-02-06 15:47:39 +0200
committerMinh Nguyễn <mxn@1ec5.org>2017-02-06 12:39:11 -0800
commit7b0881030fdc60130458c2a798de696888c87c7c (patch)
tree5c018664d3ed3ba54e973a309cd5279b7ad11afb /platform/darwin/src/MGLOfflinePack.mm
parent631c5a2f9314aaea558986f02a9b158c48fd8771 (diff)
downloadqtlocation-mapboxgl-7b0881030fdc60130458c2a798de696888c87c7c.tar.gz
Make `MGLOfflinePack` instances post notifications
This commit also gets rid of private `MGLOfflinePackDelegate` protocol. `userInfo` dictionary in notification objects retain the `state` and `progress` values for backwards compatibility. They can be removed in later major release.
Diffstat (limited to 'platform/darwin/src/MGLOfflinePack.mm')
-rw-r--r--platform/darwin/src/MGLOfflinePack.mm31
1 files changed, 27 insertions, 4 deletions
diff --git a/platform/darwin/src/MGLOfflinePack.mm b/platform/darwin/src/MGLOfflinePack.mm
index 218e32940d..60a7b55531 100644
--- a/platform/darwin/src/MGLOfflinePack.mm
+++ b/platform/darwin/src/MGLOfflinePack.mm
@@ -4,6 +4,8 @@
#import "MGLOfflineRegion_Private.h"
#import "MGLTilePyramidOfflineRegion.h"
+#import "NSValue+MGLAdditions.h"
+
#include <mbgl/storage/default_file_source.hpp>
/**
@@ -37,7 +39,6 @@ private:
@interface MGLOfflinePack ()
-@property (nonatomic, weak, nullable) id <MGLOfflinePackDelegate> delegate;
@property (nonatomic, nullable, readwrite) mbgl::OfflineRegion *mbglOfflineRegion;
@property (nonatomic, readwrite) MGLOfflinePackProgress progress;
@@ -175,7 +176,29 @@ private:
progress.maximumResourcesExpected = status.requiredResourceCountIsPrecise ? status.requiredResourceCount : UINT64_MAX;
self.progress = progress;
- [self.delegate offlinePack:self progressDidChange:progress];
+ NSDictionary *userInfo = @{MGLOfflinePackUserInfoKeyState: @(self.state),
+ MGLOfflinePackUserInfoKeyProgress: [NSValue valueWithMGLOfflinePackProgress:progress]};
+
+ NSNotificationCenter *noteCenter = [NSNotificationCenter defaultCenter];
+ [noteCenter postNotificationName:MGLOfflinePackProgressChangedNotification
+ object:self
+ userInfo:userInfo];
+}
+
+- (void)didReceiveError:(NSError *)error {
+ NSDictionary *userInfo = @{ MGLOfflinePackUserInfoKeyError: error };
+ NSNotificationCenter *noteCenter = [NSNotificationCenter defaultCenter];
+ [noteCenter postNotificationName:MGLOfflinePackErrorNotification
+ object:self
+ userInfo:userInfo];
+}
+
+- (void)didReceiveMaximumAllowedMapboxTiles:(uint64_t)limit {
+ NSDictionary *userInfo = @{ MGLOfflinePackUserInfoKeyMaximumCount: @(limit) };
+ NSNotificationCenter *noteCenter = [NSNotificationCenter defaultCenter];
+ [noteCenter postNotificationName:MGLOfflinePackMaximumMapboxTilesReachedNotification
+ object:self
+ userInfo:userInfo];
}
NSError *MGLErrorFromResponseError(mbgl::Response::Error error) {
@@ -211,12 +234,12 @@ void MBGLOfflineRegionObserver::statusChanged(mbgl::OfflineRegionStatus status)
void MBGLOfflineRegionObserver::responseError(mbgl::Response::Error error) {
dispatch_async(dispatch_get_main_queue(), ^{
- [pack.delegate offlinePack:pack didReceiveError:MGLErrorFromResponseError(error)];
+ [pack didReceiveError:MGLErrorFromResponseError(error)];
});
}
void MBGLOfflineRegionObserver::mapboxTileCountLimitExceeded(uint64_t limit) {
dispatch_async(dispatch_get_main_queue(), ^{
- [pack.delegate offlinePack:pack didReceiveMaximumAllowedMapboxTiles:limit];
+ [pack didReceiveMaximumAllowedMapboxTiles:limit];
});
}