From cbb7112e8c2a79a4777a1e439029686dc3e3547e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Wed, 13 May 2015 16:08:40 -0700 Subject: [PATCH] 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. --- platform/ios/MGLAccountManager.m | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/platform/ios/MGLAccountManager.m b/platform/ios/MGLAccountManager.m index 819dd741d..d5b89e9f9 100644 --- a/platform/ios/MGLAccountManager.m +++ b/platform/ios/MGLAccountManager.m @@ -16,15 +16,13 @@ @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 @@ + (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