blob: 82d333dc9975bd5ec990592fc7dbe99d56e20209 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#import "MGLNetworkConfiguration.h"
@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;
void (^setupBlock)() = ^{
dispatch_once(&onceToken, ^{
_sharedManager = [[self alloc] init];
});
};
if (![[NSThread currentThread] isMainThread]) {
dispatch_sync(dispatch_get_main_queue(), ^{
setupBlock();
});
} else {
setupBlock();
}
return _sharedManager;
}
+ (void)setAPIBaseURL:(NSURL *)apiBaseURL {
[MGLNetworkConfiguration sharedManager].apiBaseURL = apiBaseURL;
}
+ (NSURL *)apiBaseURL {
return [MGLNetworkConfiguration sharedManager].apiBaseURL;
}
@end
|