summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjmkiley <jordan.kiley@mapbox.com>2019-07-10 15:15:44 -0700
committerjmkiley <jordan.kiley@mapbox.com>2019-07-10 17:38:19 -0700
commitf9c4b5b44288e33c25344217f3ec8bdf11ece1fb (patch)
treec3062fb1671a2eb1e066ec40afb125105b4dc6a9
parent8ca4820573391f1c580edf4497278ce4bad72f13 (diff)
downloadqtlocation-mapboxgl-f9c4b5b44288e33c25344217f3ec8bdf11ece1fb.tar.gz
[ios] started to address jason's feedback
-rw-r--r--platform/darwin/src/MGLOfflineStorage.h2
-rw-r--r--platform/darwin/src/MGLOfflineStorage.mm43
-rw-r--r--platform/ios/app/MBXAppDelegate.m6
-rw-r--r--platform/ios/app/MBXViewController.m78
4 files changed, 28 insertions, 101 deletions
diff --git a/platform/darwin/src/MGLOfflineStorage.h b/platform/darwin/src/MGLOfflineStorage.h
index 939d0d1718..0e4e16254e 100644
--- a/platform/darwin/src/MGLOfflineStorage.h
+++ b/platform/darwin/src/MGLOfflineStorage.h
@@ -379,7 +379,7 @@ MGL_EXPORT
has been set. This handler is executed synchronously on the main queue.
*/
-- (void)setMaximumAmbientCacheSize:(NSInteger)cacheSize withCallback:(void (^)(NSError *_Nullable error))completion;
+- (void)setMaximumAmbientCacheSize:(NSUInteger)cacheSize withCallback:(void (^)(NSError *_Nullable error))completion;
/**
Checks that the tiles in the ambient cache match those from the server. Local
diff --git a/platform/darwin/src/MGLOfflineStorage.mm b/platform/darwin/src/MGLOfflineStorage.mm
index 9183096fa6..f7df2dc003 100644
--- a/platform/darwin/src/MGLOfflineStorage.mm
+++ b/platform/darwin/src/MGLOfflineStorage.mm
@@ -450,23 +450,28 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
}
- (void)invalidatePack:(MGLOfflinePack *)pack withCompletionHandler:(void (^)(NSError * _Nullable))completion {
- if (!completion) { return; }
+
mbgl::OfflineRegion& region = *pack.mbglOfflineRegion;
NSError *error;
if (!pack.mbglOfflineRegion) {
completion(nil);
- return; }
+ return;
+ }
_mbglFileSource->invalidateOfflineRegion(region, [&](std::exception_ptr exception) {
if (exception) {
- error = [NSError errorWithDomain:MGLErrorDomain code:-1 userInfo:@{
- NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()),
- }];
+ error = [NSError errorWithDomain:MGLErrorDomain
+ code:-1
+ userInfo:@{
+ NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()),
+ }];
}
});
- dispatch_async(dispatch_get_main_queue(), [&, completion, error](void) {
- completion(error);
- });
+ if (completion) {
+ dispatch_async(dispatch_get_main_queue(), [&, completion, error](void) {
+ completion(error);
+ });
+ }
}
- (void)reloadPacks {
@@ -510,7 +515,8 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
#pragma mark - Ambient Cache management
-- (void)setMaximumAmbientCacheSize:(NSInteger)cacheSize withCallback:(void (^)(NSError * _Nullable))completion {
+- (void)setMaximumAmbientCacheSize:(NSUInteger)cacheSize withCallback:(void (^)(NSError * _Nullable))completion {
+
_mbglFileSource->setMaximumAmbientCacheSize(cacheSize, [&, completion](std::exception_ptr exception) {
if (!completion) { return; }
@@ -531,7 +537,6 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
- (void)invalidateAmbientCacheWithCompletion:(void (^)(NSError *_Nullable))completion {
_mbglFileSource->invalidateAmbientCache([&, completion](std::exception_ptr exception){
- if (!completion) { return; }
NSError *error;
if (exception) {
@@ -540,16 +545,16 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()),
}];
}
-
- dispatch_async(dispatch_get_main_queue(), ^ {
- completion(error);
- });
+ if (completion) {
+ dispatch_async(dispatch_get_main_queue(), ^ {
+ completion(error);
+ });
+ }
});
}
- (void)clearAmbientCacheWithCompletion:(void (^)(NSError *_Nullable error))completion {
_mbglFileSource->clearAmbientCache([&, completion](std::exception_ptr exception){
- if (!completion) { return; }
NSError *error;
if (exception) {
error = [NSError errorWithDomain:MGLErrorDomain
@@ -557,9 +562,11 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()),
}];
}
- dispatch_async(dispatch_get_main_queue(), [&, completion, error](void) {
- completion(error);
- });
+ if (completion) {
+ dispatch_async(dispatch_get_main_queue(), [&, completion, error](void) {
+ completion(error);
+ });
+ }
});
}
diff --git a/platform/ios/app/MBXAppDelegate.m b/platform/ios/app/MBXAppDelegate.m
index 8eed4ed283..519c70766a 100644
--- a/platform/ios/app/MBXAppDelegate.m
+++ b/platform/ios/app/MBXAppDelegate.m
@@ -13,11 +13,7 @@
#ifndef MGL_DISABLE_LOGGING
[MGLLoggingConfiguration sharedConfiguration].loggingLevel = MGLLoggingLevelFault;
#endif
- [[MGLOfflineStorage sharedOfflineStorage] setMaximumAmbientCacheSize:30000000 withCallback:^(NSError * _Nullable error) {
- if (!error) {
- NSLog(@"Maximum ambient cache size: 30000000");
- }
- }];
+
[MGLMetricsManager sharedManager].delegate = self;
return YES;
}
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m
index f2893fcc26..2fb95e1b17 100644
--- a/platform/ios/app/MBXViewController.m
+++ b/platform/ios/app/MBXViewController.m
@@ -110,11 +110,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
MBXSettingsMiscellaneousSetContentInsets,
MBXSettingsMiscellaneousShowCustomLocationManager,
MBXSettingsMiscellaneousOrnamentsPlacement,
- MBXSettingsMiscellaneousInvalidateAmbientCache,
- MBXSettingsMiscellaneousClearDatabase,
- MBXSettingsMiscellaneousResetAmbientCache,
MBXSettingsMiscellaneousPrintLogFile,
- MBXSettingsMiscellaneousDeleteLogFile,
+ MBXSettingsMiscellaneousDeleteLogFile
};
// Utility methods
@@ -442,9 +439,6 @@ CLLocationCoordinate2D randomWorldCoordinate() {
[NSString stringWithFormat:@"Turn %@ Content Insets", (_contentInsetsEnabled ? @"Off" : @"On")],
@"View Route Simulation",
@"Ornaments Placement",
- @"Invalidate Ambient Cache",
- @"Reset Database",
- @"Reset Ambient Cache",
]];
if (self.currentState.debugLoggingEnabled)
@@ -774,20 +768,6 @@ CLLocationCoordinate2D randomWorldCoordinate() {
[self.navigationController pushViewController:ornamentsViewController animated:YES];
break;
}
- case MBXSettingsMiscellaneousInvalidateAmbientCache:
- {
- [self invalidateAmbientCache];
- break;
- }
- case MBXSettingsMiscellaneousClearDatabase:
- {
- [self resetDatabase];
- break;
- }
- case MBXSettingsMiscellaneousResetAmbientCache: {
- [self clearAmbientCache];
- break;
- }
default:
NSAssert(NO, @"All miscellaneous setting rows should be implemented");
break;
@@ -1785,62 +1765,6 @@ CLLocationCoordinate2D randomWorldCoordinate() {
return filePath;
}
-- (void)invalidateAmbientCache {
- CFTimeInterval start = CACurrentMediaTime();
- NSUInteger fileSize = [self getCacheSize];
- [[MGLOfflineStorage sharedOfflineStorage] invalidateAmbientCacheWithCompletion:^(NSError * _Nullable error) {
- NSInteger newFileSize = [self getCacheSize];
- NSLog(@"Ambient cache has been reloaded. Initial size: %lu New size: %lu Difference: %lu", fileSize, newFileSize, fileSize - newFileSize);
-
- CFTimeInterval end = CACurrentMediaTime();
- CFTimeInterval difference = end - start;
- NSLog(@"resetDatabase\nStarted: %f\nEnded: %f\nTotal Time: %f", start, end, difference);
- }];
-}
-
-- (void)resetDatabase {
- CFTimeInterval start = CACurrentMediaTime();
- [[MGLOfflineStorage sharedOfflineStorage] resetDatabaseWithCompletionHandler:^(NSError * _Nullable error) {
- if (!error) {
- CFTimeInterval end = CACurrentMediaTime();
- CFTimeInterval difference = end - start;
- NSLog(@"resetDatabase\nStarted: %f\nEnded: %f\nTotal Time: %f", start, end, difference);
- }
- }];
-}
-
-- (void)clearAmbientCache {
- // Access the cache.db file
- NSInteger fileSize = [self getCacheSize];
- CFTimeInterval start = CACurrentMediaTime();
- [[MGLOfflineStorage sharedOfflineStorage] clearAmbientCacheWithCompletion:^(NSError * _Nullable error) {
- NSInteger newFileSize = [self getCacheSize];
- NSLog(@"Ambient cache has been cleared. Initial size: %lu New size: %lu Difference: %lu", fileSize, newFileSize, fileSize - newFileSize);
-
- CFTimeInterval end = CACurrentMediaTime();
- CFTimeInterval difference = end - start;
- NSLog(@"clearAmbientCache\nStarted: %f\nEnded: %f\nTotal Time: %f", start, end, difference);
- }];
-}
-
-// This method is used to access the cache database file, then get the cache.db size.
-- (NSInteger)getCacheSize {
-
- NSFileManager *manager = [NSFileManager defaultManager];
- NSURL *cacheDirectoryURL = [manager URLForDirectory:NSApplicationSupportDirectory
- inDomain:NSUserDomainMask
- appropriateForURL:nil
- create:YES
- error:nil];
-
- NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
-
- NSString *urlString = [NSString stringWithFormat:@"%@/.mapbox/cache.db", bundleIdentifier];
- cacheDirectoryURL = [cacheDirectoryURL URLByAppendingPathComponent:urlString];
- NSString *path = cacheDirectoryURL.path;
- return [[manager attributesOfItemAtPath:path error:nil] fileSize];
-}
-
#pragma mark - Random World Tour
- (void)addAnnotations:(NSInteger)numAnnotations aroundCoordinate:(CLLocationCoordinate2D)coordinate radius:(CLLocationDistance)radius {