summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLOfflineStorage.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin/src/MGLOfflineStorage.mm')
-rw-r--r--platform/darwin/src/MGLOfflineStorage.mm16
1 files changed, 16 insertions, 0 deletions
diff --git a/platform/darwin/src/MGLOfflineStorage.mm b/platform/darwin/src/MGLOfflineStorage.mm
index f279235ca0..5f284b76a1 100644
--- a/platform/darwin/src/MGLOfflineStorage.mm
+++ b/platform/darwin/src/MGLOfflineStorage.mm
@@ -2,6 +2,7 @@
#import "MGLAccountManager_Private.h"
#import "MGLGeometry_Private.h"
+#import "MGLNetworkConfiguration.h"
#import "MGLOfflinePack_Private.h"
#import "MGLOfflineRegion_Private.h"
#import "MGLTilePyramidOfflineRegion.h"
@@ -127,6 +128,13 @@ NSString * const MGLOfflinePackMaximumCountUserInfoKey = @"MaximumCount";
_mbglFileSource = new mbgl::DefaultFileSource(cachePath.UTF8String, [NSBundle mainBundle].resourceURL.path.UTF8String);
+ // Observe for changes to the API base URL (and find out the current one).
+ [[MGLNetworkConfiguration sharedManager] addObserver:self
+ forKeyPath:@"apiBaseURL"
+ options:(NSKeyValueObservingOptionInitial |
+ NSKeyValueObservingOptionNew)
+ context:NULL];
+
// Observe for changes to the global access token (and find out the current one).
[[MGLAccountManager sharedManager] addObserver:self
forKeyPath:@"accessToken"
@@ -147,6 +155,7 @@ NSString * const MGLOfflinePackMaximumCountUserInfoKey = @"MaximumCount";
}
- (void)dealloc {
+ [[MGLNetworkConfiguration sharedManager] removeObserver:self forKeyPath:@"apiBaseURL"];
[[MGLAccountManager sharedManager] removeObserver:self forKeyPath:@"accessToken"];
for (MGLOfflinePack *pack in self.packs) {
@@ -164,6 +173,13 @@ NSString * const MGLOfflinePackMaximumCountUserInfoKey = @"MaximumCount";
if (![accessToken isKindOfClass:[NSNull class]]) {
self.mbglFileSource->setAccessToken(accessToken.UTF8String);
}
+ } else if ([keyPath isEqualToString:@"apiBaseURL"] && object == [MGLNetworkConfiguration sharedManager]) {
+ NSURL *apiBaseURL = change[NSKeyValueChangeNewKey];
+ if ([apiBaseURL isKindOfClass:[NSNull class]]) {
+ self.mbglFileSource->setAPIBaseURL(mbgl::util::API_BASE_URL);
+ } else {
+ self.mbglFileSource->setAPIBaseURL(apiBaseURL.absoluteString.UTF8String);
+ }
} else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}