From 860138dd384b899224742c1cb074aee3171062da Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Thu, 3 Dec 2015 14:48:15 -0800 Subject: [PATCH] record app fg/bg/inactive state in telemetry --- platform/ios/MGLMapboxEvents.m | 39 +++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/platform/ios/MGLMapboxEvents.m b/platform/ios/MGLMapboxEvents.m index 7f8df6109..259cfb3de 100644 --- a/platform/ios/MGLMapboxEvents.m +++ b/platform/ios/MGLMapboxEvents.m @@ -495,7 +495,9 @@ const NSTimeInterval MGLFlushInterval = 60; MGLReachability *reachability = [MGLReachability reachabilityForLocalWiFi]; [evt setValue:([reachability isReachableViaWiFi] ? @YES : @NO) forKey:@"wifi"]; - + + [evt setValue:[strongSelf applicationState] forKey:@"applicationState"]; + [evt setValue:@([strongSelf contentSizeScale]) forKey:@"accessibilityFontScale"]; // Make Immutable Version @@ -653,6 +655,41 @@ const NSTimeInterval MGLFlushInterval = 60; return result; } +// Can be called from any thread. +// +- (NSString *) applicationState { + __block NSString *result; + + NSString *(^applicationStateBlock)(void) = ^{ + switch ([UIApplication sharedApplication].applicationState) { + case UIApplicationStateActive: + result = @"Active"; + break; + case UIApplicationStateInactive: + result = @"Inactive"; + break; + case UIApplicationStateBackground: + result = @"Background"; + break; + default: + result = @"Default - Unknown"; + break; + } + + return result; + }; + + if ( ! [[NSThread currentThread] isMainThread]) { + dispatch_sync(dispatch_get_main_queue(), ^{ + result = applicationStateBlock(); + }); + } else { + result = applicationStateBlock(); + } + + return result; +} + // Can be called from any thread. // - (NSInteger) contentSizeScale {