diff options
author | Jesse Bounds <jesse@rebounds.net> | 2018-01-08 15:47:22 -0800 |
---|---|---|
committer | Fabian Guerra <fabian.guerra@mapbox.com> | 2018-02-19 16:08:18 -0500 |
commit | 6fccfe354845fea5f49a1c3b8108972f71a74508 (patch) | |
tree | 6259c4aee1f7f859070699a861e976aa1c0a3366 | |
parent | 19a4a52ca5699e576b11c4f981b71e48feabe18c (diff) | |
download | qtlocation-mapboxgl-6fccfe354845fea5f49a1c3b8108972f71a74508.tar.gz |
Add comments about config value loading
-rw-r--r-- | platform/ios/src/MGLMapboxEvents.m | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/platform/ios/src/MGLMapboxEvents.m b/platform/ios/src/MGLMapboxEvents.m index c8a86c9d8d..e22484ec7d 100644 --- a/platform/ios/src/MGLMapboxEvents.m +++ b/platform/ios/src/MGLMapboxEvents.m @@ -40,6 +40,10 @@ static NSString * const MGLAPIClientUserAgentBase = @"MapboxEventsiOS"; _eventsManager.accountType = [[NSUserDefaults standardUserDefaults] integerForKey:@"MGLMapboxAccountType"]; _eventsManager.metricsEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"MGLMapboxMetricsEnabled"]; + // Because we can get here [MGLAccountManaber +load] it is possible that values from user defaults will be read and + // applied here. These checks and local accessToken and baseURL assigns work around that fact. If user default value + // are set, they are stored on the local properties here and then only applied later on once MMEEventsManager is + // fully initialized (once -[MMEEventsManager initializeWithAccessToken:userAgentBase:hostSDKVersion:] is called. if ([[[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys] containsObject:@"MGLTelemetryAccessToken"]) { self.accessToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"MGLTelemetryAccessToken"]; } @@ -58,16 +62,21 @@ static NSString * const MGLAPIClientUserAgentBase = @"MapboxEventsiOS"; - (void)userDefaultsDidChange:(NSNotification *)notification { dispatch_async(dispatch_get_main_queue(), ^{ - - // Default values self.eventsManager.metricsEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"MGLMapboxMetricsEnabled"]; self.eventsManager.accountType = [[NSUserDefaults standardUserDefaults] integerForKey:@"MGLMapboxAccountType"]; self.eventsManager.debugLoggingEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"MGLMapboxMetricsDebugLoggingEnabled"]; - // Optional values + + // It is possible that MGLTelemetryAccessToken is set and userDefaultsDidChange: is called before setupWithAccessToken: is called. + // In that case, setting the access token here will be a noop. In practice, that's fine because the access token value + // will be resolved when setupWithAccessToken: is called eventually if ([[[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys] containsObject:@"MGLTelemetryAccessToken"]) { self.eventsManager.accessToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"MGLTelemetryAccessToken"]; } + + // It is possible that MGLTelemetryBaseURL is set and userDefaultsDidChange: is called before setupWithAccessToken: is called. + // In that case, setting baseURL here will be a noop. In practice, that's fine because the baseURL value + // will be resolved when setupWithAccessToken: is called eventually if ([[[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys] containsObject:@"MGLTelemetryBaseURL"]) { NSURL *baseURL = [NSURL URLWithString:[[NSUserDefaults standardUserDefaults] objectForKey:@"MGLTelemetryBaseURL"]]; self.eventsManager.baseURL = baseURL; |