This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1225 - Initial setup of MapboxGL as a singleton object with access t…
…oken
- Loading branch information
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
#import "MapboxGL.h" | ||
|
||
@interface MapboxGL() | ||
|
||
@end | ||
|
||
@property (atomic) NSString *accessToken; | ||
|
||
@implementation MapboxGL | ||
|
||
|
||
// Can be called from any thread. Called implicitly from any | ||
// public class convenience methods. | ||
// | ||
+ (instancetype) sharedInstanceWithAccessToken:(NSString *)token { | ||
static dispatch_once_t onceToken; | ||
static MapboxGL *_sharedManager; | ||
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; | ||
} | ||
|
||
@end |