#1225 - Initial setup of MapboxGL as a singleton object with access token
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
'../platform/darwin/image.mm',
|
||||
'../platform/darwin/reachability.m',
|
||||
'../include/mbgl/ios/MapboxGL.h',
|
||||
'../platform/ios/MapboxGL.m',
|
||||
'../include/mbgl/ios/MGLMapboxEvents.h',
|
||||
'../platform/ios/MGLMapboxEvents.m',
|
||||
'../include/mbgl/ios/MGLMapView.h',
|
||||
|
||||
@@ -2,3 +2,9 @@
|
||||
#import "MGLMapView.h"
|
||||
#import "MGLTypes.h"
|
||||
#import "MGLUserLocation.h"
|
||||
|
||||
@interface MapboxGL : NSObject
|
||||
|
||||
+ (void) sharedInstanceWithAccessToken:(NSString *)token;
|
||||
|
||||
@end
|
||||
39
platform/ios/MapboxGL.m
Normal file
39
platform/ios/MapboxGL.m
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user