summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gyp/platform-ios.gypi1
-rw-r--r--platform/ios/MGLAccountManager.m2
-rw-r--r--platform/ios/MGLAccountManager_Private.h10
-rw-r--r--platform/ios/MGLMapView.mm22
4 files changed, 30 insertions, 5 deletions
diff --git a/gyp/platform-ios.gypi b/gyp/platform-ios.gypi
index 7e91648c40..12cbd9592c 100644
--- a/gyp/platform-ios.gypi
+++ b/gyp/platform-ios.gypi
@@ -27,6 +27,7 @@
'../platform/ios/MGLFileCache.h',
'../platform/ios/MGLFileCache.mm',
'../include/mbgl/ios/MGLAccountManager.h',
+ '../platform/ios/MGLAccountManager_Private.h',
'../platform/ios/MGLAccountManager.m',
'../include/mbgl/ios/MGLAnnotation.h',
'../include/mbgl/ios/MGLUserLocation.h',
diff --git a/platform/ios/MGLAccountManager.m b/platform/ios/MGLAccountManager.m
index 97d7e5e5ec..38ef1f4ca9 100644
--- a/platform/ios/MGLAccountManager.m
+++ b/platform/ios/MGLAccountManager.m
@@ -1,6 +1,6 @@
#import <Foundation/Foundation.h>
-#import "MGLAccountManager.h"
+#import "MGLAccountManager_Private.h"
#import "MGLMapboxEvents_Private.h"
#import "NSProcessInfo+MGLAdditions.h"
diff --git a/platform/ios/MGLAccountManager_Private.h b/platform/ios/MGLAccountManager_Private.h
new file mode 100644
index 0000000000..3cc05b09f0
--- /dev/null
+++ b/platform/ios/MGLAccountManager_Private.h
@@ -0,0 +1,10 @@
+#import "MGLAccountManager.h"
+
+@interface MGLAccountManager (Private)
+
+/** Returns the shared instance of the `MGLAccountManager` class. */
++ (instancetype)sharedManager;
+
+@property (atomic) NSString *accessToken;
+
+@end
diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm
index cb89c58d46..997d5734aa 100644
--- a/platform/ios/MGLMapView.mm
+++ b/platform/ios/MGLMapView.mm
@@ -20,7 +20,7 @@
#import "NSString+MGLAdditions.h"
#import "NSProcessInfo+MGLAdditions.h"
#import "NSException+MGLAdditions.h"
-#import "MGLAccountManager.h"
+#import "MGLAccountManager_Private.h"
#import "MGLAnnotation.h"
#import "MGLUserLocationAnnotationView.h"
#import "MGLUserLocation_Private.h"
@@ -266,9 +266,12 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
}
_mbglMap->resize(self.bounds.size.width, self.bounds.size.height, _glView.contentScaleFactor);
- // mbgl::Map keeps its own copy of the access token.
- NSString *accessToken = [MGLAccountManager accessToken];
- _mbglMap->setAccessToken(accessToken ? (std::string)[accessToken UTF8String] : "");
+ // Observe for changes to the global access token (and find out the current one).
+ [[MGLAccountManager sharedManager] addObserver:self
+ forKeyPath:@"accessToken"
+ options:(NSKeyValueObservingOptionInitial |
+ NSKeyValueObservingOptionNew)
+ context:NULL];
// Notify map object when network reachability status changes.
[[NSNotificationCenter defaultCenter] addObserver:self
@@ -410,6 +413,7 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
[_regionChangeDelegateQueue cancelAllOperations];
[[NSNotificationCenter defaultCenter] removeObserver:self];
+ [[MGLAccountManager sharedManager] removeObserver:self forKeyPath:@"accessToken"];
if (_mbglMap)
{
@@ -1292,6 +1296,16 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
#pragma mark - Properties -
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(__unused void *)context
+{
+ // Synchronize mbgl::Map’s access token with the global one in MGLAccountManager.
+ if ([keyPath isEqualToString:@"accessToken"] && object == [MGLAccountManager sharedManager])
+ {
+ NSString *accessToken = change[NSKeyValueChangeNewKey];
+ _mbglMap->setAccessToken(accessToken ? (std::string)[accessToken UTF8String] : "");
+ }
+}
+
+ (NSSet *)keyPathsForValuesAffectingZoomEnabled
{
return [NSSet setWithObject:@"allowsZooming"];