summaryrefslogtreecommitdiff
path: root/platform/ios/MapboxGL.m
blob: 0c88128215885ba87c76fdfffa275581129d0084 (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
44
45
46
47
48
#import <Foundation/Foundation.h>

#import "MapboxGL.h"
#import "NSProcessInfo+MGLAdditions.h"

@interface MapboxGL()

@property (atomic) NSString *accessToken;

@end


@implementation MapboxGL

static MapboxGL *_sharedManager;

// Can be called from any thread. Called implicitly from any
// public class convenience methods.
//
+ (instancetype) sharedInstanceWithAccessToken:(NSString *)token {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if ( ! NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent) {
            void (^setupBlock)() = ^{
                _sharedManager = [[self alloc] init];
                _sharedManager.accessToken = token;
            };
            if ( ! [[NSThread currentThread] isMainThread]) {
                dispatch_sync(dispatch_get_main_queue(), ^{
                    setupBlock();
                });
            }
            else {
                setupBlock();
            }
        }
    });
    return _sharedManager;
}

+ (NSString *) getAccessToken {
    if (_sharedManager) {
        return _sharedManager.accessToken;
    }
    return nil;
}

@end