diff --git a/include/mbgl/ios/MGLAccountManager.h b/include/mbgl/ios/MGLAccountManager.h index c1b7406b9..f856f16cc 100644 --- a/include/mbgl/ios/MGLAccountManager.h +++ b/include/mbgl/ios/MGLAccountManager.h @@ -1,5 +1,6 @@ @interface MGLAccountManager : NSObject ++ (void) setMapboxMetricsEnabledSettingShownInApp:(BOOL)showsOptOut; + (void) setAccessToken:(NSString *) accessToken; + (NSString *) accessToken; diff --git a/ios/app/MBXAppDelegate.m b/ios/app/MBXAppDelegate.m index 90c552aba..d4af1f59d 100644 --- a/ios/app/MBXAppDelegate.m +++ b/ios/app/MBXAppDelegate.m @@ -21,6 +21,9 @@ } if ( ! accessToken) NSLog(@"No access token set. Mapbox vector tiles won't work."); + // Signal To SDK That Opt Out Is In App UI +// [MGLAccountManager setShowsOptOutInApp:YES]; + // Start Mapbox GL SDK [MGLAccountManager setAccessToken:accessToken]; diff --git a/platform/ios/MGLAccountManager.m b/platform/ios/MGLAccountManager.m index b1a80fd6a..09bfb3db2 100644 --- a/platform/ios/MGLAccountManager.m +++ b/platform/ios/MGLAccountManager.m @@ -6,6 +6,7 @@ @interface MGLAccountManager() +@property (atomic) BOOL showsOptOutInApp; @property (atomic) NSString *accessToken; @end @@ -23,6 +24,7 @@ static MGLAccountManager *_sharedManager; if ( ! NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent) { void (^setupBlock)() = ^{ _sharedManager = [[self alloc] init]; + _sharedManager.showsOptOutInApp = NO; }; if ( ! [[NSThread currentThread] isMainThread]) { dispatch_sync(dispatch_get_main_queue(), ^{ @@ -37,6 +39,14 @@ static MGLAccountManager *_sharedManager; return _sharedManager; } ++ (void) setMapboxMetricsEnabledSettingShownInApp:(BOOL)showsOptOut { + [MGLAccountManager sharedInstance].showsOptOutInApp = showsOptOut; +} + ++ (BOOL) mapboxMetricsEnabledSettingShownInApp { + return [MGLAccountManager sharedInstance].showsOptOutInApp; +} + + (void) setAccessToken:(NSString *) accessToken { [[MGLAccountManager sharedInstance] setAccessToken:accessToken]; diff --git a/platform/ios/MGLMapboxEvents.m b/platform/ios/MGLMapboxEvents.m index 3a6559b76..244928f95 100644 --- a/platform/ios/MGLMapboxEvents.m +++ b/platform/ios/MGLMapboxEvents.m @@ -9,6 +9,7 @@ #import "NSProcessInfo+MGLAdditions.h" #import "NSBundle+MGLAdditions.h" #import "NSException+MGLAdditions.h" +#import "MGLAccountManager.m" #include @@ -117,11 +118,13 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; self = [super init]; if (self) { - // Put Settings bundle into memory - NSString *appSettingsBundle = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"]; - if(!appSettingsBundle) { - NSLog(@"Could not find Settings.bundle"); - } else { + if (! [MGLAccountManager mapboxMetricsEnabledSettingShownInApp]) { + // Opt Out is not configured in UI, so check for Settings.bundle + // Put Settings bundle into memory + NSString *appSettingsBundle = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"]; + + NSAssert(appSettingsBundle, @"End users must be able to opt out of Metrics in your app, either via the Settings.bundle or in the app itself which must be noted via setting +[MGLAccountManager setShowsOptOutInApp:YES]"); + // Dynamic Settings.bundle loading based on: // http://stackoverflow.com/questions/510216/can-you-make-the-settings-in-settings-bundle-default-even-if-you-dont-open-the NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[appSettingsBundle stringByAppendingPathComponent:@"Root.plist"]]; @@ -133,9 +136,10 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; [defaultsToRegister setObject:[prefSpecification objectForKey:@"DefaultValue"] forKey:key]; } } - + [[NSUserDefaults standardUserDefaults] registerDefaults:defaultsToRegister]; } + _appBundleId = [[NSBundle mainBundle] bundleIdentifier]; NSString *uniqueID = [[NSProcessInfo processInfo] globallyUniqueString]; _serialQueue = dispatch_queue_create([[NSString stringWithFormat:@"%@.%@.events.serial", _appBundleId, uniqueID] UTF8String], DISPATCH_QUEUE_SERIAL);