From 5656477af104817ed71a976835896f15f653f695 Mon Sep 17 00:00:00 2001 From: jmkiley Date: Thu, 18 Jul 2019 16:56:42 -0700 Subject: [ios] Add example to debug menu --- platform/ios/app/MBXViewController.m | 75 ++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 3 deletions(-) diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 2fb95e1b17..ad2dce4e45 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -49,7 +49,10 @@ typedef NS_ENUM(NSInteger, MBXSettingsDebugToolsRows) { MBXSettingsDebugToolsOverdrawVisualization, MBXSettingsDebugToolsShowZoomLevel, MBXSettingsDebugToolsShowFrameTimeGraph, - MBXSettingsDebugToolsShowReuseQueueStats + MBXSettingsDebugToolsShowReuseQueueStats, + MBXSettingsDebugToolsInvalidateAmbientCache, + MBXSettingsDebugToolsClearAmbientCache, + MBXSettingsDebugToolsResetDatabase }; typedef NS_ENUM(NSInteger, MBXSettingsAnnotationsRows) { @@ -375,7 +378,10 @@ CLLocationCoordinate2D randomWorldCoordinate() { (debugMask & MGLMapDebugOverdrawVisualizationMask ? @"Hide" :@"Show")], [NSString stringWithFormat:@"%@ zoom level ornament", (self.zoomLevelOrnamentEnabled ? @"Hide" :@"Show")], [NSString stringWithFormat:@"%@ frame time graph", (self.frameTimeGraphEnabled ? @"Hide" :@"Show")], - [NSString stringWithFormat:@"%@ reuse queue stats", (self.reuseQueueStatsEnabled ? @"Hide" :@"Show")] + [NSString stringWithFormat:@"%@ reuse queue stats", (self.reuseQueueStatsEnabled ? @"Hide" :@"Show")], + @"Invalidate Ambient Cache", + @"Clear Ambient Cache", + @"Reset Database", ]]; break; case MBXSettingsAnnotations: @@ -508,11 +514,19 @@ CLLocationCoordinate2D randomWorldCoordinate() { [self updateHUD]; break; } + case MBXSettingsDebugToolsInvalidateAmbientCache: + [self invalidateAmbientCache]; + break; + case MBXSettingsDebugToolsClearAmbientCache: + [self clearAmbientCache]; + break; + case MBXSettingsDebugToolsResetDatabase: + [self resetDatabase]; + break; default: NSAssert(NO, @"All debug tools setting rows should be implemented"); break; } - self.mapView.debugMask = self.currentState.debugMask; break; @@ -1765,6 +1779,61 @@ CLLocationCoordinate2D randomWorldCoordinate() { return filePath; } +#pragma mark: +- (void)invalidateAmbientCache { + CFTimeInterval start = CACurrentMediaTime(); + [[MGLOfflineStorage sharedOfflineStorage] invalidateAmbientCacheWithCompletionHandler:^(NSError * _Nullable error) { + if (error) { + NSLog(@"Error: %@", error.localizedDescription); + return; + } else { + CFTimeInterval difference = CACurrentMediaTime() - start; + NSLog(@"Ambient cache invalidated in %f seconds", difference); + } + }]; +} + +- (void)invalidateOfflinePack { + CFTimeInterval start = CACurrentMediaTime(); + MGLOfflinePack *pack = [MGLOfflineStorage sharedOfflineStorage].packs.firstObject; + + [[MGLOfflineStorage sharedOfflineStorage] invalidatePack:pack withCompletionHandler:^(NSError * _Nullable error) { + if (error) { + NSLog(@"Error: %@", error.localizedDescription); + return; + } else { + CFTimeInterval difference = CACurrentMediaTime() - start; + NSLog(@"Offline pack invalidated in %f seconds", difference); + } + }]; +} + +- (void)clearAmbientCache { + CFTimeInterval start = CACurrentMediaTime(); + [[MGLOfflineStorage sharedOfflineStorage] clearAmbientCacheWithCompletionHandler:^(NSError * _Nullable error) { + if (error) { + NSLog(@"Error: %@", error.localizedDescription); + return; + } else { + CFTimeInterval difference = CACurrentMediaTime() - start; + NSLog(@"Ambient cache cleared in %f seconds", difference); + } + }]; +} + +- (void)resetDatabase { + CFTimeInterval start = CACurrentMediaTime(); + [[MGLOfflineStorage sharedOfflineStorage] resetDatabaseWithCompletionHandler:^(NSError * _Nullable error) { + if (error) { + NSLog(@"Error: %@", error.localizedDescription); + return; + } else { + CFTimeInterval difference = CACurrentMediaTime() - start; + NSLog(@"Database reset in %f seconds", difference); + } + }]; +} + #pragma mark - Random World Tour - (void)addAnnotations:(NSInteger)numAnnotations aroundCoordinate:(CLLocationCoordinate2D)coordinate radius:(CLLocationDistance)radius { -- cgit v1.2.1