Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Grab app-wide data from Info.plist #1553

Merged
merged 8 commits into from
May 20, 2015
Prev Previous commit
Next Next commit
Set up MGLAccountManager without any prodding
`MGLAccountManager` is now guaranteed to initialize without the code ever making any mention of it. It also is guaranteed to be set up before `MGLMapboxMetrics` but will definitely cause `MGLMapboxMetrics` to be set up on the main thread if the access token is set in Info.plist.
1ec5 committed May 13, 2015
commit cbb7112e8c2a79a4777a1e439029686dc3e3547e
18 changes: 8 additions & 10 deletions platform/ios/MGLAccountManager.m
Original file line number Diff line number Diff line change
@@ -16,15 +16,13 @@ + (void)setMapboxMetricsEnabledSettingShownInApp:(BOOL)showsOptOut;

@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];
}
+ (void)load {
// 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];
}
}

@@ -63,7 +61,7 @@ + (BOOL) mapboxMetricsEnabledSettingShownInApp {
+ (void) setAccessToken:(NSString *) accessToken {
if ( ! [accessToken length]) return;

[[MGLAccountManager sharedManager] setAccessToken:accessToken];
[MGLAccountManager sharedManager].accessToken = accessToken;

// Update MGLMapboxEvents
// NOTE: This is (likely) the initial setup of MGLMapboxEvents