summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-03-26 14:38:07 -0700
committerMinh Nguyễn <mxn@1ec5.org>2016-03-29 11:46:26 -0700
commite36f31c50302dc2194cc34fab7b89d9cef8c87a5 (patch)
treef130ddf8770b92ae91416b819b5d233932c09881 /platform
parentec72faa7891a24795c9b040076de829642be043d (diff)
downloadqtlocation-mapboxgl-e36f31c50302dc2194cc34fab7b89d9cef8c87a5.tar.gz
[ios, osx] Allow creating invalid offline packs
Removed NS_UNAVAILABLE attribute from -[MGLOfflinePack init]. Packs initialized with this initializer are doomed to invalidity. Fixes #4421.
Diffstat (limited to 'platform')
-rw-r--r--platform/darwin/include/MGLOfflinePack.h6
-rw-r--r--platform/darwin/src/MGLOfflinePack.mm12
-rw-r--r--platform/darwin/src/MGLOfflineStorage.mm5
3 files changed, 15 insertions, 8 deletions
diff --git a/platform/darwin/include/MGLOfflinePack.h b/platform/darwin/include/MGLOfflinePack.h
index 666e442d26..185bba038c 100644
--- a/platform/darwin/include/MGLOfflinePack.h
+++ b/platform/darwin/include/MGLOfflinePack.h
@@ -83,6 +83,10 @@ typedef struct MGLOfflinePackProgress {
/**
An `MGLOfflinePack` represents a collection of resources necessary for viewing
a region offline to a local database.
+
+ To create an instance of `MGLOfflinePack`, use the
+ `+[MGLOfflineStorage addPackForRegion:withContext:completionHandler:]` method.
+ A pack created using `-[MGLOfflinePack init]` is immediately invalid.
*/
@interface MGLOfflinePack : NSObject
@@ -123,8 +127,6 @@ typedef struct MGLOfflinePackProgress {
*/
@property (nonatomic, readonly) MGLOfflinePackProgress progress;
-- (instancetype)init NS_UNAVAILABLE;
-
/**
Resumes downloading if the pack is inactive.
diff --git a/platform/darwin/src/MGLOfflinePack.mm b/platform/darwin/src/MGLOfflinePack.mm
index 279261e9be..30b268aaf1 100644
--- a/platform/darwin/src/MGLOfflinePack.mm
+++ b/platform/darwin/src/MGLOfflinePack.mm
@@ -48,11 +48,11 @@ private:
@implementation MGLOfflinePack
- (instancetype)init {
- [NSException raise:@"Method unavailable"
- format:
- @"-[MGLOfflinePack init] is unavailable. "
- @"Use +[MGLOfflineStorage addPackForRegion:withContext:completionHandler:] instead."];
- return nil;
+ if (self = [super init]) {
+ _state = MGLOfflinePackStateInvalid;
+ NSLog(@"%s called; did you mean to call +[MGLOfflineStorage addPackForRegion:withContext:completionHandler:] instead?", __PRETTY_FUNCTION__);
+ }
+ return self;
}
- (instancetype)initWithMBGLRegion:(mbgl::OfflineRegion *)region {
@@ -123,7 +123,7 @@ private:
}
- (void)requestProgress {
- MGLAssertOfflinePackIsValid();
+ NSAssert(_state != MGLOfflinePackStateInvalid, @"Cannot request progress from an invalid offline pack.");
mbgl::DefaultFileSource *mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource];
diff --git a/platform/darwin/src/MGLOfflineStorage.mm b/platform/darwin/src/MGLOfflineStorage.mm
index c4c57224da..4555f03001 100644
--- a/platform/darwin/src/MGLOfflineStorage.mm
+++ b/platform/darwin/src/MGLOfflineStorage.mm
@@ -178,6 +178,11 @@ NSString * const MGLOfflinePackMaximumCountUserInfoKey = @"MaximumCount";
- (void)_removePack:(MGLOfflinePack *)pack withCompletionHandler:(MGLOfflinePackRemovalCompletionHandler)completion {
mbgl::OfflineRegion *mbglOfflineRegion = pack.mbglOfflineRegion;
[pack invalidate];
+ if (!mbglOfflineRegion) {
+ completion(nil);
+ return;
+ }
+
self.mbglFileSource->deleteOfflineRegion(std::move(*mbglOfflineRegion), [&, completion](std::exception_ptr exception) {
NSError *error;
if (exception) {