53 lines
1.3 KiB
Objective-C
53 lines
1.3 KiB
Objective-C
#import <Foundation/Foundation.h>
|
|
|
|
#import "MGLAccountManager.h"
|
|
#import "NSProcessInfo+MGLAdditions.h"
|
|
#import "MGLMapboxEvents.h"
|
|
|
|
@interface MGLAccountManager()
|
|
|
|
@property (atomic) NSString *accessToken;
|
|
|
|
@end
|
|
|
|
|
|
@implementation MGLAccountManager
|
|
|
|
static MGLAccountManager *_sharedManager;
|
|
|
|
// Can be called from any thread.
|
|
//
|
|
+ (instancetype) sharedInstance {
|
|
static dispatch_once_t onceToken;
|
|
dispatch_once(&onceToken, ^{
|
|
if ( ! NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent) {
|
|
void (^setupBlock)() = ^{
|
|
_sharedManager = [[self alloc] init];
|
|
};
|
|
if ( ! [[NSThread currentThread] isMainThread]) {
|
|
dispatch_sync(dispatch_get_main_queue(), ^{
|
|
setupBlock();
|
|
});
|
|
}
|
|
else {
|
|
setupBlock();
|
|
}
|
|
}
|
|
});
|
|
return _sharedManager;
|
|
}
|
|
|
|
+ (void) setAccessToken:(NSString *) accessToken {
|
|
[[MGLAccountManager sharedInstance] setAccessToken:accessToken];
|
|
|
|
// Update MGLMapboxEvents
|
|
// NOTE: This is (likely) the initial setup of MGLMapboxEvents
|
|
[MGLMapboxEvents setToken:accessToken];
|
|
}
|
|
|
|
+ (NSString *) accessToken {
|
|
return [MGLAccountManager sharedInstance].accessToken;
|
|
}
|
|
|
|
|
|
@end |