diff options
Diffstat (limited to 'platform')
-rw-r--r-- | platform/ios/MGLAccountManager.m | 10 | ||||
-rw-r--r-- | platform/ios/MGLMapboxEvents.m | 16 |
2 files changed, 20 insertions, 6 deletions
diff --git a/platform/ios/MGLAccountManager.m b/platform/ios/MGLAccountManager.m index b1a80fd6a7..09bfb3db23 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 3a6559b766..244928f95c 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 <sys/sysctl.h> @@ -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); |