From bf6a100801639f5a5c190fb43233a8e2cfb98dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Wed, 17 Jun 2015 16:49:12 -0700 Subject: [PATCH] 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. --- platform/ios/MGLAccountManager.m | 5 ++++- platform/ios/MGLMapView.mm | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/platform/ios/MGLAccountManager.m b/platform/ios/MGLAccountManager.m index d391ea881..710ddd3e3 100644 --- a/platform/ios/MGLAccountManager.m +++ b/platform/ios/MGLAccountManager.m @@ -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. diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index 40eeec0ec..efb428cb5 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -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]); + } } }