blob: d661d9090e68b20f44f6ba50abbfd8b1fc0c20e8 (
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
40
41
42
43
|
#import "MGLNetworkConfiguration.h"
#import "NSProcessInfo+MGLAdditions.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 {
if (NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent) {
return nil;
}
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
|