summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2015-05-13 15:33:28 -0700
committerMinh Nguyễn <mxn@1ec5.org>2015-05-13 15:33:28 -0700
commit2529baa62b509f2c763d5b3f9f5e1e388a45917f (patch)
tree432738db3298518ee2c150fff53fe41efe68f20e
parent1d38b636402a6581c491185090f5c81495a07d13 (diff)
downloadqtlocation-mapboxgl-2529baa62b509f2c763d5b3f9f5e1e388a45917f.tar.gz
Grab access token and other app-wide data from Info.plist
That way there’s no ambiguity about when you should call things like `+[MGLAccountManager setMapboxMetricsEnabledSettingShownInApp:]`. In fact, that method is now deprecated because it’s so easy to call in the wrong place. Fixes #1535.
-rw-r--r--include/mbgl/ios/MGLAccountManager.h2
-rw-r--r--platform/ios/MGLAccountManager.m17
-rw-r--r--platform/ios/MGLMapboxEvents.m4
3 files changed, 20 insertions, 3 deletions
diff --git a/include/mbgl/ios/MGLAccountManager.h b/include/mbgl/ios/MGLAccountManager.h
index 7ec4135f18..5c1b2e3579 100644
--- a/include/mbgl/ios/MGLAccountManager.h
+++ b/include/mbgl/ios/MGLAccountManager.h
@@ -21,7 +21,7 @@
/** Certain Mapbox plans require the collection of user metrics. If you aren't using a preference switch in an existing or new `Settings.bundle` in your application, set this value to `YES` to indicate that you are providing a metrics opt-out for users within your app's interface directly.
* @param showsOptOut Whether your application's interface provides a user opt-out preference. The default value is `NO`, meaning a `Settings.bundle` is expected for providing a user opt-out preference. */
-+ (void)setMapboxMetricsEnabledSettingShownInApp:(BOOL)showsOptOut;
++ (void)setMapboxMetricsEnabledSettingShownInApp:(BOOL)showsOptOut DEPRECATED_MSG_ATTRIBUTE("Set MGLMapboxMetricsEnabledSettingShownInApp in Info.plist");
/** Whether in-app user metrics opt-out is configured. If set to the default value of `NO`, a user opt-out preference is expected in a `Settings.bundle` that shows in the application's section within the system Settings app. */
+ (BOOL)mapboxMetricsEnabledSettingShownInApp;
diff --git a/platform/ios/MGLAccountManager.m b/platform/ios/MGLAccountManager.m
index 2e3c0a38e4..819dd741d9 100644
--- a/platform/ios/MGLAccountManager.m
+++ b/platform/ios/MGLAccountManager.m
@@ -9,11 +9,25 @@
@property (atomic) BOOL mapboxMetricsEnabledSettingShownInApp;
@property (atomic) NSString *accessToken;
++ (void)setMapboxMetricsEnabledSettingShownInApp:(BOOL)showsOptOut;
+
@end
@implementation MGLAccountManager
++ (void)initialize {
+ if (self == [MGLAccountManager class]) {
+ // Read initial configuration from Info.plist.
+ NSBundle *bundle = [NSBundle bundleForClass:self];
+ self.accessToken = [bundle objectForInfoDictionaryKey:@"MGLMapboxAccessToken"];
+ NSNumber *shownInAppNumber = [bundle objectForInfoDictionaryKey:@"MGLMapboxMetricsEnabledSettingShownInApp"];
+ if (shownInAppNumber) {
+ [MGLAccountManager sharedManager].mapboxMetricsEnabledSettingShownInApp = [shownInAppNumber boolValue];
+ }
+ }
+}
+
// Can be called from any thread.
//
+ (instancetype) sharedManager {
@@ -25,7 +39,6 @@
void (^setupBlock)() = ^{
dispatch_once(&onceToken, ^{
_sharedManager = [[self alloc] init];
- _sharedManager.mapboxMetricsEnabledSettingShownInApp = NO;
});
};
if ( ! [[NSThread currentThread] isMainThread]) {
@@ -48,6 +61,8 @@
}
+ (void) setAccessToken:(NSString *) accessToken {
+ if ( ! [accessToken length]) return;
+
[[MGLAccountManager sharedManager] setAccessToken:accessToken];
// Update MGLMapboxEvents
diff --git a/platform/ios/MGLMapboxEvents.m b/platform/ios/MGLMapboxEvents.m
index 2b9d887777..017dceeb37 100644
--- a/platform/ios/MGLMapboxEvents.m
+++ b/platform/ios/MGLMapboxEvents.m
@@ -176,8 +176,10 @@ const NSTimeInterval MGLFlushInterval = 60;
+ (void)initialize {
if (self == [MGLMapboxEvents class]) {
+ NSBundle *bundle = [NSBundle bundleForClass:self];
+ NSNumber *accountTypeNumber = [bundle objectForInfoDictionaryKey:@"MGLMapboxAccountType"];
[[NSUserDefaults standardUserDefaults] registerDefaults:@{
- @"MGLMapboxAccountType": @0,
+ @"MGLMapboxAccountType": accountTypeNumber ? accountTypeNumber : @0,
@"MGLMapboxMetricsEnabled": @YES,
}];
}