summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gyp/platform-ios.gypi1
-rw-r--r--include/mbgl/ios/MapboxGL.h6
-rw-r--r--platform/ios/MapboxGL.m39
3 files changed, 46 insertions, 0 deletions
diff --git a/gyp/platform-ios.gypi b/gyp/platform-ios.gypi
index f707431182..142896c4ee 100644
--- a/gyp/platform-ios.gypi
+++ b/gyp/platform-ios.gypi
@@ -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',
diff --git a/include/mbgl/ios/MapboxGL.h b/include/mbgl/ios/MapboxGL.h
index c32915bc76..84c3f45429 100644
--- a/include/mbgl/ios/MapboxGL.h
+++ b/include/mbgl/ios/MapboxGL.h
@@ -2,3 +2,9 @@
#import "MGLMapView.h"
#import "MGLTypes.h"
#import "MGLUserLocation.h"
+
+@interface MapboxGL : NSObject
+
++ (void) sharedInstanceWithAccessToken:(NSString *)token;
+
+@end \ No newline at end of file
diff --git a/platform/ios/MapboxGL.m b/platform/ios/MapboxGL.m
new file mode 100644
index 0000000000..b1cb44cbc9
--- /dev/null
+++ b/platform/ios/MapboxGL.m
@@ -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 \ No newline at end of file