summaryrefslogtreecommitdiff
path: root/platform/ios/MGLMapboxEvents.m
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2015-05-12 15:26:07 -0700
committerMinh Nguyễn <mxn@1ec5.org>2015-05-12 15:26:07 -0700
commitafbb9c27170475e28edb04a97fc92fef2160ea5d (patch)
tree45d0017b24d8f19c5b6a828d58bac877c93dfbe1 /platform/ios/MGLMapboxEvents.m
parent50d7add6b0edeaaf22a3a035d2bbff1c13a08669 (diff)
downloadqtlocation-mapboxgl-afbb9c27170475e28edb04a97fc92fef2160ea5d.tar.gz
Enable Metrics by default default default
Enable Mapbox Metrics by default when Settings.bundle is absent, but allow Settings.bundle to override the default. Don’t register defaults for non-Mapbox preferences. The two-phase registration ensures that the defaults don’t default to unexpected values, yet gives the developer a chance to call `+[MGLAccountManager mapboxMetricsEnabledSettingShownInApp]` before the hard assertion. Fixes #1518.
Diffstat (limited to 'platform/ios/MGLMapboxEvents.m')
-rw-r--r--platform/ios/MGLMapboxEvents.m35
1 files changed, 23 insertions, 12 deletions
diff --git a/platform/ios/MGLMapboxEvents.m b/platform/ios/MGLMapboxEvents.m
index cb4cdce60b..2864f0a49f 100644
--- a/platform/ios/MGLMapboxEvents.m
+++ b/platform/ios/MGLMapboxEvents.m
@@ -110,6 +110,15 @@ NSString *const MGLEventGestureRotateStart = @"Rotation";
@implementation MGLMapboxEvents
++ (void)initialize {
+ if (self == [MGLMapboxEvents class]) {
+ [[NSUserDefaults standardUserDefaults] registerDefaults:@{
+ @"MGLMapboxAccountType": @0,
+ @"MGLMapboxMetricsEnabled": @YES,
+ }];
+ }
+}
+
// Must be called from the main thread. Only called internally.
//
- (instancetype) init {
@@ -121,23 +130,25 @@ NSString *const MGLEventGestureRotateStart = @"Rotation";
if (! [MGLAccountManager mapboxMetricsEnabledSettingShownInApp]) {
// Opt Out is not configured in UI, so check for Settings.bundle
// Put Settings bundle into memory
+ id defaultEnabledValue;
NSString *appSettingsBundle = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"];
- NSAssert(appSettingsBundle, @"End users must be able to opt out of Metrics in your app, either inside Settings (via Settings.bundle) or inside this app. If you implement the opt-out control inside this app, disable this assertion by setting [MGLAccountManager setMapboxMetricsEnabledSettingShownInApp:YES] before the app initializes any Mapbox GL classes.");
-
- // 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"]];
- NSArray *preferences = [settings objectForKey:@"PreferenceSpecifiers"];
- NSMutableDictionary *defaultsToRegister = [[NSMutableDictionary alloc] initWithCapacity:[preferences count]];
- for(NSDictionary *prefSpecification in preferences) {
- NSString *key = [prefSpecification objectForKey:@"Key"];
- if(key && [[prefSpecification allKeys] containsObject:@"DefaultValue"]) {
- [defaultsToRegister setObject:[prefSpecification objectForKey:@"DefaultValue"] forKey:key];
+ if (appSettingsBundle) {
+ // 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"]];
+ NSArray *preferences = settings[@"PreferenceSpecifiers"];
+ for (NSDictionary *prefSpecification in preferences) {
+ if ([prefSpecification[@"Key"] isEqualToString:@"MGLMapboxMetricsEnabled"]) {
+ defaultEnabledValue = prefSpecification[@"DefaultValue"];
+ }
}
}
- [[NSUserDefaults standardUserDefaults] registerDefaults:defaultsToRegister];
+ NSAssert(defaultEnabledValue, @"End users must be able to opt out of Metrics in your app, either inside Settings (via Settings.bundle) or inside this app. If you implement the opt-out control inside this app, disable this assertion by setting [MGLAccountManager setMapboxMetricsEnabledSettingShownInApp:YES] before the app initializes any Mapbox GL classes.");
+ [[NSUserDefaults standardUserDefaults] registerDefaults:@{
+ @"MGLMapboxMetricsEnabled": defaultEnabledValue,
+ }];
}
_appBundleId = [[NSBundle mainBundle] bundleIdentifier];