summaryrefslogtreecommitdiff
path: root/platform/darwin
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin')
-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
5 files changed, 27 insertions, 29 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);