Merge pull request #1520 from mapbox/1516-opt-out-checking

Explicit Opt Out Checking
This commit is contained in:
Brad Leege
2015-05-12 11:04:14 -05:00
committed by Justin R. Miller
parent bc7e2b9b94
commit 0a1e89a9ca
4 changed files with 24 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
@interface MGLAccountManager : NSObject
+ (void) setMapboxMetricsEnabledSettingShownInApp:(BOOL)showsOptOut;
+ (void) setAccessToken:(NSString *) accessToken;
+ (NSString *) accessToken;

View File

@@ -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];

View File

@@ -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];

View File

@@ -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);