#1225 - Initial setup of MapboxGL as a singleton object with access token

This commit is contained in:
Brad Leege
2015-04-22 17:19:59 -05:00
parent 1008787745
commit 578d48b303
3 changed files with 46 additions and 0 deletions

View File

@@ -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',

View File

@@ -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
View 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