Avoid null-change KVO notifications

If no access token is set in the Info.plist, avoid triggering a KVO notification about the access token changing. By the same token (heh), avoid pulling a C string out of the change dictionary if the access token is being nilled out.
This commit is contained in:
Minh Nguyễn
2015-06-17 16:49:12 -07:00
parent dcbb5b2e4e
commit bf6a100801
2 changed files with 7 additions and 2 deletions

View File

@@ -21,7 +21,10 @@
if (shownInAppNumber) {
[MGLAccountManager sharedManager].mapboxMetricsEnabledSettingShownInApp = [shownInAppNumber boolValue];
}
self.accessToken = [bundle objectForInfoDictionaryKey:@"MGLMapboxAccessToken"];
NSString *accessToken = [bundle objectForInfoDictionaryKey:@"MGLMapboxAccessToken"];
if (accessToken.length) {
self.accessToken = accessToken;
}
}
// Can be called from any thread.

View File

@@ -1290,7 +1290,9 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
if ([keyPath isEqualToString:@"accessToken"] && object == [MGLAccountManager sharedManager])
{
NSString *accessToken = change[NSKeyValueChangeNewKey];
_mbglFileSource->setAccessToken(accessToken ? (std::string)[accessToken UTF8String] : "");
if (![accessToken isKindOfClass:[NSNull class]]) {
_mbglFileSource->setAccessToken((std::string)[accessToken UTF8String]);
}
}
}