From 4092e469829e7cc14e946b2ed4e413091bd63b3b Mon Sep 17 00:00:00 2001 From: Brad Leege Date: Mon, 6 Apr 2015 23:03:27 -0500 Subject: [PATCH] #1216 - Add pause and resume methods with corresponding isPaused boolean flag property --- include/mbgl/ios/MGLMapboxEvents.h | 2 ++ platform/ios/MGLMapboxEvents.m | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/mbgl/ios/MGLMapboxEvents.h b/include/mbgl/ios/MGLMapboxEvents.h index e51371368..2af3d8b16 100644 --- a/include/mbgl/ios/MGLMapboxEvents.h +++ b/include/mbgl/ios/MGLMapboxEvents.h @@ -29,6 +29,8 @@ extern NSString *const MGLEventGestureRotateStart; + (void) setToken:(NSString *)token; + (void) setAppName:(NSString *)appName; + (void) setAppVersion:(NSString *)appVersion; ++ (void) pauseMetricsCollection; ++ (void) resumeMetricsCollection; // You can call this method from any thread. Significant work will // be dispatched to a low-priority background queue and all diff --git a/platform/ios/MGLMapboxEvents.m b/platform/ios/MGLMapboxEvents.m index 2dfecbd77..593a98390 100644 --- a/platform/ios/MGLMapboxEvents.m +++ b/platform/ios/MGLMapboxEvents.m @@ -71,6 +71,11 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; @property (atomic) NSDateFormatter *rfc3339DateFormatter; @property (atomic) CGFloat scale; + +// The isPaused state tracker is only ever accessed from the main thread. +// +@property (nonatomic) BOOL isPaused; + // The timer is only ever accessed from the main thread. // @property (nonatomic) NSTimer *timer; @@ -168,6 +173,8 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; // Clear Any System TimeZone Cache [NSTimeZone resetSystemTimeZone]; [_rfc3339DateFormatter setTimeZone:[NSTimeZone systemTimeZone]]; + + _isPaused = NO; } return self; } @@ -219,6 +226,20 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; [MGLMapboxEvents sharedManager].appVersion = appVersion; } +// Must be called from the main thread. +// ++ (void) pauseMetricsCollection { + assert([[NSThread currentThread] isMainThread]); + [MGLMapboxEvents sharedManager].isPaused = YES; +} + +// Must be called from the main thread. +// ++ (void) resumeMetricsCollection { + assert([[NSThread currentThread] isMainThread]); + [MGLMapboxEvents sharedManager].isPaused = NO; +} + // Can be called from any thread. Can be called rapidly from // the UI thread, so performance is paramount. //