summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjmkiley <jordan.kiley@mapbox.com>2019-06-27 10:51:22 -0700
committerjmkiley <jordan.kiley@mapbox.com>2019-07-09 15:03:39 -0700
commit9fc03e461dbfdd281d6dd231cdc3ee1786ab5cd9 (patch)
treef9d55a62752ba3d6e28ec88a9eaee8e77224a413
parentbefd28d0cfe8d1381951b544f3662defa34247dd (diff)
downloadqtlocation-mapboxgl-9fc03e461dbfdd281d6dd231cdc3ee1786ab5cd9.tar.gz
[ios] Added implementations and started debug code
-rw-r--r--platform/darwin/src/MGLOfflineStorage.h2
-rw-r--r--platform/darwin/src/MGLOfflineStorage.mm65
-rw-r--r--platform/ios/app/MBXAppDelegate.m5
-rw-r--r--platform/ios/app/MBXViewController.m72
4 files changed, 125 insertions, 19 deletions
diff --git a/platform/darwin/src/MGLOfflineStorage.h b/platform/darwin/src/MGLOfflineStorage.h
index 0306d84114..bb8eff6c88 100644
--- a/platform/darwin/src/MGLOfflineStorage.h
+++ b/platform/darwin/src/MGLOfflineStorage.h
@@ -359,7 +359,7 @@ MGL_EXPORT
- (void)invalidateAmbientCacheWithCompletion:(void (^)(NSError *_Nullable error))completion;
-- (void)clearAmbientCache;
+- (void)clearAmbientCacheWithCompletion:(void (^)(NSError *_Nullable error))completion;
/*
Inserts the provided resource into the ambient cache.
diff --git a/platform/darwin/src/MGLOfflineStorage.mm b/platform/darwin/src/MGLOfflineStorage.mm
index c9ec84a852..72d69a1eeb 100644
--- a/platform/darwin/src/MGLOfflineStorage.mm
+++ b/platform/darwin/src/MGLOfflineStorage.mm
@@ -445,6 +445,20 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
});
}
+- (void)invalidateOfflineRegion:(MGLShapeOfflineRegion *)region withCompletionHandler:(void (^)(NSError * _Nullable))completion {
+ if (!completion) { return; }
+ const mbgl::OfflineRegionDefinition mbglRegionDefinition = [(id <MGLOfflineRegion_Private>)region offlineRegionDefinition];
+ // JK - I need to convert the MGLOfflineRegion to an OfflineRegion
+
+// _mbglFileSource->invalidateOfflineRegion(std::move *region, [&, completion](std::exception_ptr exception) {
+// NSError *error;
+// if (error) {
+// error = [NSError errorWithDomain:MGLErrorDomain code:-1 userInfo:@{
+//
+// }];
+// }
+// });
+}
- (void)reloadPacks {
MGLLogInfo(@"Reloading packs.");
[self getPacksWithCompletionHandler:^(NSArray<MGLOfflinePack *> *packs, __unused NSError * _Nullable error) {
@@ -486,41 +500,58 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
#pragma mark - Ambient Cache management
-- (void)setMaximumAmbientCacheSize:(NSInteger)cacheSize withCallback:(void (^)(NSError * _Nullable error))completion {
+- (void)setMaximumAmbientCacheSize:(NSInteger)cacheSize withCallback:(void (^)(NSError * _Nullable))completion {
_mbglFileSource->setMaximumAmbientCacheSize(cacheSize, [&, completion](std::exception_ptr exception) {
+ if (!completion) { return; }
+
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);
- });
+ error = [NSError errorWithDomain:MGLErrorDomain
+ code:-1
+ userInfo:@{
+ NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()),
+ }
+ ];
}
+ dispatch_async(dispatch_get_main_queue(), ^ {
+ completion(error);
+ });
});
}
-- (void)invalidateAmbientCacheWithCompletion:(void (^)(NSError *_Nullable error))completion {
+- (void)invalidateAmbientCacheWithCompletion:(void (^)(NSError *_Nullable))completion {
_mbglFileSource->invalidateAmbientCache([&, completion](std::exception_ptr exception){
+ if (!completion) { return; }
+
NSError *error;
if (exception) {
+ // Convert std::exception_ptr to an NSError.
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);
- });
- }
+
+ dispatch_async(dispatch_get_main_queue(), ^ {
+ completion(error);
+ });
});
}
-- (void)clearAmbientCache {
-
+- (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
+ code:-1 userInfo:@{
+ NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()),
+ }];
+ }
+ dispatch_async(dispatch_get_main_queue(), [&, completion, error](void) {
+ completion(error);
+ });
+ });
}
#pragma mark -
diff --git a/platform/ios/app/MBXAppDelegate.m b/platform/ios/app/MBXAppDelegate.m
index 519c70766a..27d45c7615 100644
--- a/platform/ios/app/MBXAppDelegate.m
+++ b/platform/ios/app/MBXAppDelegate.m
@@ -14,6 +14,11 @@
[MGLLoggingConfiguration sharedConfiguration].loggingLevel = MGLLoggingLevelFault;
#endif
+ [[MGLOfflineStorage sharedOfflineStorage] setMaximumAmbientCacheSize:30 withCallback:^(NSError * _Nullable error) {
+ if (!error) {
+ NSLog(@"Maximum ambient cache size: 30");
+ }
+ }];
[MGLMetricsManager sharedManager].delegate = self;
return YES;
}
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m
index 2fb95e1b17..f774b7f5bc 100644
--- a/platform/ios/app/MBXViewController.m
+++ b/platform/ios/app/MBXViewController.m
@@ -110,8 +110,11 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
MBXSettingsMiscellaneousSetContentInsets,
MBXSettingsMiscellaneousShowCustomLocationManager,
MBXSettingsMiscellaneousOrnamentsPlacement,
+ MBXSettingsMiscellaneousInvalidateAmbientCache,
+ MBXSettingsMiscellaneousClearDatabase,
+ MBXSettingsMiscellaneousResetAmbientCache,
MBXSettingsMiscellaneousPrintLogFile,
- MBXSettingsMiscellaneousDeleteLogFile
+ MBXSettingsMiscellaneousDeleteLogFile,
};
// Utility methods
@@ -439,6 +442,9 @@ CLLocationCoordinate2D randomWorldCoordinate() {
[NSString stringWithFormat:@"Turn %@ Content Insets", (_contentInsetsEnabled ? @"Off" : @"On")],
@"View Route Simulation",
@"Ornaments Placement",
+ @"Invalidate Ambient Cache",
+ @"Clear Database",
+ @"Reset Ambient Cache",
]];
if (self.currentState.debugLoggingEnabled)
@@ -768,6 +774,20 @@ 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;
@@ -1765,6 +1785,56 @@ CLLocationCoordinate2D randomWorldCoordinate() {
return filePath;
}
+// Getting a bad access exception
+- (void)invalidateAmbientCache {
+ __block NSString *path = [self getCachePath];
+ NSFileManager *manager = [NSFileManager defaultManager];
+ unsigned long long fileSize = [[manager attributesOfItemAtPath:path error:nil] fileSize];
+ NSLog(@"CACHE SIZE: %llu", fileSize);
+
+ [[MGLOfflineStorage sharedOfflineStorage] invalidateAmbientCacheWithCompletion:^(NSError * _Nullable error) {
+ NSLog(@"Ambient cache has been reloaded!");
+ path = [self getCachePath];
+ unsigned long long newFileSize = [[manager attributesOfItemAtPath:path error:nil] fileSize];
+ NSLog(@"CACHE SIZE: %llu", newFileSize);
+ }];
+}
+
+- (void)resetDatabase {
+
+}
+
+- (void)clearAmbientCache {
+ // Access the cache.db file
+ __block NSString *path = [self getCachePath];
+ NSFileManager *manager = [NSFileManager defaultManager];
+ unsigned long long fileSize = [[manager attributesOfItemAtPath:path error:nil] fileSize];
+ NSLog(@"CACHE SIZE: %llu", fileSize);
+ [[MGLOfflineStorage sharedOfflineStorage] clearAmbientCacheWithCompletion:^(NSError * _Nullable error) {
+ NSLog(@"DONE");
+ path = [self getCachePath];
+ unsigned long long newFileSize = [[manager attributesOfItemAtPath:path error:nil] fileSize];
+ NSLog(@"CACHE SIZE: %llu", newFileSize);
+ }];
+}
+
+// This method is used to access the cache database file.
+- (NSString *)getCachePath {
+ NSURL *cacheDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory
+ inDomain:NSUserDomainMask
+ appropriateForURL:nil
+ create:YES
+ error:nil];
+
+ NSBundle *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
+
+ // Can I do this in
+ cacheDirectoryURL = [cacheDirectoryURL URLByAppendingPathComponent:bundleIdentifier];
+ cacheDirectoryURL = [cacheDirectoryURL URLByAppendingPathComponent:@".mapbox/cache.db"];
+// cacheDirectoryURL = [cacheDirectoryURL URLByAppendingPathComponent:@""];
+ return cacheDirectoryURL.path;
+}
+
#pragma mark - Random World Tour
- (void)addAnnotations:(NSInteger)numAnnotations aroundCoordinate:(CLLocationCoordinate2D)coordinate radius:(CLLocationDistance)radius {