[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.
This commit is contained in:
committed by
Minh Nguyễn
parent
ec72faa789
commit
e36f31c503
@@ -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.
|
||||
|
||||
|
||||
@@ -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];
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user