diff options
author | jmkiley <jordan.kiley@mapbox.com> | 2019-06-25 15:49:49 -0700 |
---|---|---|
committer | jmkiley <jordan.kiley@mapbox.com> | 2019-07-09 15:03:39 -0700 |
commit | befd28d0cfe8d1381951b544f3662defa34247dd (patch) | |
tree | 298401f53b93f27a3f21a65605fddddcd159b51d | |
parent | 474fe9f5fee3a393efddf5be04f0062693c5f486 (diff) | |
download | qtlocation-mapboxgl-befd28d0cfe8d1381951b544f3662defa34247dd.tar.gz |
[ios] chipping at methods
-rw-r--r-- | platform/darwin/src/MGLOfflineStorage.h | 5 | ||||
-rw-r--r-- | platform/darwin/src/MGLOfflineStorage.mm | 48 |
2 files changed, 30 insertions, 23 deletions
diff --git a/platform/darwin/src/MGLOfflineStorage.h b/platform/darwin/src/MGLOfflineStorage.h index 8ec70a7c7d..0306d84114 100644 --- a/platform/darwin/src/MGLOfflineStorage.h +++ b/platform/darwin/src/MGLOfflineStorage.h @@ -351,14 +351,13 @@ MGL_EXPORT This method should be called before using the database. */ - -- (void)setMaximumAmbientCacheSize:(void (^)(unsigned long cacheSize, NSError * _Nullable error))completion; +- (void)setMaximumAmbientCacheSize:(NSInteger)cacheSize withCallback:(void (^)(NSError *_Nullable error))completion; /* Forces cache tiles to be invalidated and updated from the tile server. This ensures that the */ -- (void)invalidateAmbientCache; +- (void)invalidateAmbientCacheWithCompletion:(void (^)(NSError *_Nullable error))completion; - (void)clearAmbientCache; diff --git a/platform/darwin/src/MGLOfflineStorage.mm b/platform/darwin/src/MGLOfflineStorage.mm index c7462b5548..c9ec84a852 100644 --- a/platform/darwin/src/MGLOfflineStorage.mm +++ b/platform/darwin/src/MGLOfflineStorage.mm @@ -48,7 +48,6 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio @property (nonatomic) std::shared_ptr<mbgl::DefaultFileSource> mbglFileSource; @property (nonatomic) std::string mbglCachePath; @property (nonatomic, getter=isPaused) BOOL paused; - @end @implementation MGLOfflineStorage { @@ -431,7 +430,6 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio completion(nil); return; } - _mbglFileSource->deleteOfflineRegion(std::move(*mbglOfflineRegion), [&, completion](std::exception_ptr exception) { NSError *error; if (exception) { @@ -488,27 +486,37 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio #pragma mark - Ambient Cache management +- (void)setMaximumAmbientCacheSize:(NSInteger)cacheSize withCallback:(void (^)(NSError * _Nullable error))completion { -void maxCacheSizeCallback(std::exception_ptr result) { - - - - // if ( ! (cacheSize > 0) ) { /* give a warning*/ } ; - - // - // ERROR: Too few arguments to function call, expected 2, + _mbglFileSource->setMaximumAmbientCacheSize(cacheSize, [&, completion](std::exception_ptr exception) { + NSError *error; + if (exception) { + error = [NSError errorWithDomain:MGLErrorDomain code:-1 userInfo:@{ + NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()), + }]; + } + if (completion) { + dispatch_async(dispatch_get_main_queue(), [&, completion, error](void) { + completion(error); + }); + } + }); } -- (void)setMaximumAmbientCacheSize:(NSInteger)cacheSize withCallback:(void (^)(NSError *))callback { - - - _mbglFileSource->setMaximumAmbientCacheSize(cacheSize, maxCacheSizeCallback); - - } - -- (void)invalidateAmbientCache { - _mbglFileSource->invalidateAmbientCache(nil); - // Do something with the std::exception_ptr here +- (void)invalidateAmbientCacheWithCompletion:(void (^)(NSError *_Nullable error))completion { + _mbglFileSource->invalidateAmbientCache([&, completion](std::exception_ptr exception){ + NSError *error; + if (exception) { + error = [NSError errorWithDomain:MGLErrorDomain code:-1 userInfo:@{ + NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()), + }]; + } + if (completion) { + dispatch_async(dispatch_get_main_queue(), [&, completion, error](void) { + completion(error); + }); + } + }); } - (void)clearAmbientCache { |