diff --git a/ios/app/MBXAppDelegate.m b/ios/app/MBXAppDelegate.m index f0541b997..8c5947354 100644 --- a/ios/app/MBXAppDelegate.m +++ b/ios/app/MBXAppDelegate.m @@ -1,5 +1,6 @@ #import "MBXAppDelegate.h" #import "MBXViewController.h" +#import @implementation MBXAppDelegate @@ -12,4 +13,15 @@ return YES; } +- (void)applicationWillEnterForeground:(UIApplication *)application +{ + [MGLMapboxEvents resumeMetricsCollection]; +} + +- (void)applicationDidEnterBackground:(UIApplication *)application +{ + [MGLMapboxEvents pauseMetricsCollection]; +} + + @end diff --git a/platform/ios/MGLMapboxEvents.m b/platform/ios/MGLMapboxEvents.m index 0f3422b86..346bd70ac 100644 --- a/platform/ios/MGLMapboxEvents.m +++ b/platform/ios/MGLMapboxEvents.m @@ -230,6 +230,9 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; // + (void) pauseMetricsCollection { assert([[NSThread currentThread] isMainThread]); + if ([MGLMapboxEvents sharedManager].isPaused) { + return; + } [MGLMapboxEvents sharedManager].isPaused = YES; [MGLMetricsLocationManager stopUpdatingLocation]; } @@ -238,6 +241,9 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; // + (void) resumeMetricsCollection { assert([[NSThread currentThread] isMainThread]); + if (![MGLMapboxEvents sharedManager].isPaused) { + return; + } [MGLMapboxEvents sharedManager].isPaused = NO; [MGLMetricsLocationManager startUpdatingLocation]; }