summaryrefslogtreecommitdiff
path: root/platform
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 /platform
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.
Diffstat (limited to 'platform')
-rw-r--r--platform/ios/MGLAccountManager.m17
-rw-r--r--platform/ios/MGLMapboxEvents.m4
2 files changed, 19 insertions, 2 deletions
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,
}];
}