From 48e21ae6e915aecf24022e7ba568d436d876160b Mon Sep 17 00:00:00 2001 From: Brad Leege Date: Mon, 11 May 2015 23:31:22 -0500 Subject: [PATCH] #1516 - Adding explicit checks for developer implementation of user Opt Out functionality --- include/mbgl/ios/MGLAccountManager.h | 1 + ios/app/MBXAppDelegate.m | 3 +++ platform/ios/MGLAccountManager.m | 10 ++++++++++ platform/ios/MGLMapboxEvents.m | 20 ++++++++++++++------ 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/include/mbgl/ios/MGLAccountManager.h b/include/mbgl/ios/MGLAccountManager.h index c1b7406b9..7f4d0a556 100644 --- a/include/mbgl/ios/MGLAccountManager.h +++ b/include/mbgl/ios/MGLAccountManager.h @@ -1,5 +1,6 @@ @interface MGLAccountManager : NSObject ++ (void) setShowsOptOutInApp:(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..f93f379f4 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) setShowsOptOutInApp:(BOOL)showsOptOut { + [[MGLAccountManager sharedInstance] setShowsOptOutInApp:showsOptOut]; +} + ++ (BOOL) showsOptOutInApp { + 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..0246d429e 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 sharedInstance].showsOptOutInApp) { + // 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); @@ -242,6 +246,10 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; [self pauseMetricsCollection]; } ++ (void) setShowsOptOutInApp:(BOOL)showsOptOut { + +} + // Must be called from the main thread. // + (void) setToken:(NSString *)token {