diff options
author | Justin R. Miller <incanus@users.noreply.github.com> | 2016-10-15 20:12:36 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-15 20:12:36 -0700 |
commit | 674304bfae3b8ed9625d0de2f59d5eedcffaf143 (patch) | |
tree | 32b1a3c08ab0046db5ad1db269c8fa36963176c4 /platform/darwin/src/MGLOfflineStorage.mm | |
parent | e5a473a30181b8790743f12e1a4f7a0e300eb8b4 (diff) | |
download | qtlocation-mapboxgl-674304bfae3b8ed9625d0de2f59d5eedcffaf143.tar.gz |
[ios, macos] fixes #6346: add support for configurable API base URL (#6709)
Diffstat (limited to 'platform/darwin/src/MGLOfflineStorage.mm')
-rw-r--r-- | platform/darwin/src/MGLOfflineStorage.mm | 16 |
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]; } |