[ios, macos] Move apiBaseURL to MGLAccountManager` (#13754)
[ios, macos] Move `apiBaseURL` to `MGLAccountManager`
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 */,
|
||||
|
||||
Reference in New Issue
Block a user