summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Kiley <jmkiley@users.noreply.github.com>2019-02-13 13:20:48 -0800
committerGitHub <noreply@github.com>2019-02-13 13:20:48 -0800
commit5d8505603099cad3334dc95297f9ca8dd2e103a0 (patch)
tree0a9ed3129a1896d6ac2ebedef04f19b1321785f5
parent98eac18a2133a7beda12fdfc27d6f88217d800cf (diff)
downloadqtlocation-mapboxgl-5d8505603099cad3334dc95297f9ca8dd2e103a0.tar.gz
[ios, macos] Move `apiBaseURL` to `MGLAccountManager`` (#13754)
[ios, macos] Move `apiBaseURL` to `MGLAccountManager`
-rw-r--r--platform/darwin/src/MGLAccountManager.m17
-rw-r--r--platform/darwin/src/MGLAccountManager_Private.h3
-rw-r--r--platform/darwin/src/MGLNetworkConfiguration.h7
-rw-r--r--platform/darwin/src/MGLNetworkConfiguration.m16
-rw-r--r--platform/darwin/src/MGLOfflineStorage.mm13
-rw-r--r--platform/ios/ios.xcodeproj/project.pbxproj4
6 files changed, 27 insertions, 33 deletions
diff --git a/platform/darwin/src/MGLAccountManager.m b/platform/darwin/src/MGLAccountManager.m
index 4a3f698427..d914867628 100644
--- a/platform/darwin/src/MGLAccountManager.m
+++ b/platform/darwin/src/MGLAccountManager.m
@@ -8,12 +8,14 @@
@interface MGLAccountManager ()
@property (atomic) NSString *accessToken;
+@property (nonatomic) NSURL *apiBaseURL;
@end
#else
@interface MGLAccountManager ()
@property (atomic) NSString *accessToken;
+@property (nonatomic) NSURL *apiBaseURL;
@end
#endif
@@ -28,6 +30,13 @@
if (accessToken.length) {
self.accessToken = accessToken;
}
+
+ NSString *apiBaseURL = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"MGLMapboxAPIBaseURL"];
+
+ // If apiBaseURL is not a valid URL, [NSURL URLWithString:] will be `nil`.
+ if (apiBaseURL.length && [NSURL URLWithString:apiBaseURL]) {
+ [self setAPIBaseURL:[NSURL URLWithString:apiBaseURL]];
+ }
}
+ (instancetype)sharedManager {
@@ -71,4 +80,12 @@
return [MGLAccountManager sharedManager].accessToken;
}
++ (void)setAPIBaseURL:(NSURL *)apiBaseURL {
+ [MGLAccountManager sharedManager].apiBaseURL = apiBaseURL;
+}
+
++ (NSURL *)apiBaseURL {
+ return [MGLAccountManager sharedManager].apiBaseURL;
+}
+
@end
diff --git a/platform/darwin/src/MGLAccountManager_Private.h b/platform/darwin/src/MGLAccountManager_Private.h
index b68016b1a7..4644635940 100644
--- a/platform/darwin/src/MGLAccountManager_Private.h
+++ b/platform/darwin/src/MGLAccountManager_Private.h
@@ -8,4 +8,7 @@
/// The current global access token.
@property (atomic) NSString *accessToken;
+/// The API base URL that is used to access Mapbox resources. The default base URL is `https://api.mapbox.com`. If `nil`, the Mapbox default base API URL is in use.
+@property (atomic, readwrite) NSURL *apiBaseURL;
+
@end
diff --git a/platform/darwin/src/MGLNetworkConfiguration.h b/platform/darwin/src/MGLNetworkConfiguration.h
index 2db46d78c5..aaac5a330c 100644
--- a/platform/darwin/src/MGLNetworkConfiguration.h
+++ b/platform/darwin/src/MGLNetworkConfiguration.h
@@ -6,18 +6,13 @@ NS_ASSUME_NONNULL_BEGIN
The MGLNetworkConfiguration object provides a global way to set a base API URL for
retrieval of map data, styles, and other resources.
- Currently, MGLNetworkConfiguration is private API in code but is able to be used
- by any applications via the `MGLMapboxAPIBaseURL` dictionary key in the
- application's `Info.plist`.
+ Currently, MGLNetworkConfiguration is a private API.
*/
@interface MGLNetworkConfiguration : NSObject
/// Returns the shared instance of the `MGLNetworkConfiguration` class.
@property (class, nonatomic, readonly) MGLNetworkConfiguration *sharedManager;
-/// The current API base URL. If `nil`, the Mapbox default base API URL is in use.
-@property (atomic, nullable) NSURL *apiBaseURL;
-
@end
NS_ASSUME_NONNULL_END
diff --git a/platform/darwin/src/MGLNetworkConfiguration.m b/platform/darwin/src/MGLNetworkConfiguration.m
index 4cfa405a1a..61422f7caa 100644
--- a/platform/darwin/src/MGLNetworkConfiguration.m
+++ b/platform/darwin/src/MGLNetworkConfiguration.m
@@ -2,14 +2,6 @@
@implementation MGLNetworkConfiguration
-+ (void)load {
- // Read the initial configuration from Info.plist.
- NSString *apiBaseURL = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"MGLMapboxAPIBaseURL"];
- if (apiBaseURL.length) {
- [self setAPIBaseURL:[NSURL URLWithString:apiBaseURL]];
- }
-}
-
+ (instancetype)sharedManager {
static dispatch_once_t onceToken;
static MGLNetworkConfiguration *_sharedManager;
@@ -28,12 +20,4 @@
return _sharedManager;
}
-+ (void)setAPIBaseURL:(NSURL *)apiBaseURL {
- [MGLNetworkConfiguration sharedManager].apiBaseURL = apiBaseURL;
-}
-
-+ (NSURL *)apiBaseURL {
- return [MGLNetworkConfiguration sharedManager].apiBaseURL;
-}
-
@end
diff --git a/platform/darwin/src/MGLOfflineStorage.mm b/platform/darwin/src/MGLOfflineStorage.mm
index 17c1ff3d29..4613b402fd 100644
--- a/platform/darwin/src/MGLOfflineStorage.mm
+++ b/platform/darwin/src/MGLOfflineStorage.mm
@@ -3,7 +3,6 @@
#import "MGLFoundation_Private.h"
#import "MGLAccountManager_Private.h"
#import "MGLGeometry_Private.h"
-#import "MGLNetworkConfiguration.h"
#import "MGLOfflinePack_Private.h"
#import "MGLOfflineRegion_Private.h"
#import "MGLTilePyramidOfflineRegion.h"
@@ -227,11 +226,11 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
_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 |
+ [[MGLAccountManager sharedManager] addObserver:self
+ forKeyPath:@"apiBaseURL"
+ options:(NSKeyValueObservingOptionInitial |
NSKeyValueObservingOptionNew)
- context:NULL];
+ context:NULL];
// Observe for changes to the global access token (and find out the current one).
[[MGLAccountManager sharedManager] addObserver:self
@@ -245,7 +244,7 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
- [[MGLNetworkConfiguration sharedManager] removeObserver:self forKeyPath:@"apiBaseURL"];
+ [[MGLAccountManager sharedManager] removeObserver:self forKeyPath:@"apiBaseURL"];
[[MGLAccountManager sharedManager] removeObserver:self forKeyPath:@"accessToken"];
for (MGLOfflinePack *pack in self.packs) {
@@ -263,7 +262,7 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
if (![accessToken isKindOfClass:[NSNull class]]) {
self.mbglFileSource->setAccessToken(accessToken.UTF8String);
}
- } else if ([keyPath isEqualToString:@"apiBaseURL"] && object == [MGLNetworkConfiguration sharedManager]) {
+ } else if ([keyPath isEqualToString:@"apiBaseURL"] && object == [MGLAccountManager sharedManager]) {
NSURL *apiBaseURL = change[NSKeyValueChangeNewKey];
if ([apiBaseURL isKindOfClass:[NSNull class]]) {
self.mbglFileSource->setAPIBaseURL(mbgl::util::API_BASE_URL);
diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj
index 2857d503bb..8d5a725848 100644
--- a/platform/ios/ios.xcodeproj/project.pbxproj
+++ b/platform/ios/ios.xcodeproj/project.pbxproj
@@ -474,8 +474,6 @@
CA0C27942076CA19001CE5B7 /* MGLMapViewIntegrationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CA0C27932076CA19001CE5B7 /* MGLMapViewIntegrationTest.m */; };
CA1B4A512099FB2200EDD491 /* MGLMapSnapshotterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CA1B4A502099FB2200EDD491 /* MGLMapSnapshotterTest.m */; };
CA34C9C3207FD272005C1A06 /* MGLCameraTransitionTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = CA34C9C2207FD272005C1A06 /* MGLCameraTransitionTests.mm */; };
- CA45105A21EE2989000C37D5 /* MGLCompactCalloutView.m in Sources */ = {isa = PBXBuildFile; fileRef = DA8848451CBAFB9800AB86E3 /* MGLCompactCalloutView.m */; };
- CA45105B21EE29B3000C37D5 /* SMCalloutView.m in Sources */ = {isa = PBXBuildFile; fileRef = DA88488A1CBB037E00AB86E3 /* SMCalloutView.m */; };
CA4EB8C720863487006AB465 /* MGLStyleLayerIntegrationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CA4EB8C620863487006AB465 /* MGLStyleLayerIntegrationTests.m */; };
CA55CD41202C16AA00CE7095 /* MGLCameraChangeReason.h in Headers */ = {isa = PBXBuildFile; fileRef = CA55CD3E202C16AA00CE7095 /* MGLCameraChangeReason.h */; settings = {ATTRIBUTES = (Public, ); }; };
CA55CD42202C16AA00CE7095 /* MGLCameraChangeReason.h in Headers */ = {isa = PBXBuildFile; fileRef = CA55CD3E202C16AA00CE7095 /* MGLCameraChangeReason.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -3042,12 +3040,10 @@
buildActionMask = 2147483647;
files = (
CA4EB8C720863487006AB465 /* MGLStyleLayerIntegrationTests.m in Sources */,
- CA45105B21EE29B3000C37D5 /* SMCalloutView.m in Sources */,
CA34C9C3207FD272005C1A06 /* MGLCameraTransitionTests.mm in Sources */,
16376B0A1FFD9DAF0000563E /* MBGLIntegrationTests.m in Sources */,
CA88DC3021C85D900059ED5A /* MGLStyleURLIntegrationTest.m in Sources */,
CA0C27942076CA19001CE5B7 /* MGLMapViewIntegrationTest.m in Sources */,
- CA45105A21EE2989000C37D5 /* MGLCompactCalloutView.m in Sources */,
CAE7AD5520F46EF5003B6782 /* MGLMapSnapshotterSwiftTests.swift in Sources */,
CA0C27922076C804001CE5B7 /* MGLShapeSourceTests.m in Sources */,
077061DA215DA00E000FEF62 /* MGLTestLocationManager.m in Sources */,