From 578d48b303d5d615ac70f9f1f6f3edfef020d8a3 Mon Sep 17 00:00:00 2001 From: Brad Leege Date: Wed, 22 Apr 2015 17:19:59 -0500 Subject: [PATCH] #1225 - Initial setup of MapboxGL as a singleton object with access token --- gyp/platform-ios.gypi | 1 + include/mbgl/ios/MapboxGL.h | 6 ++++++ platform/ios/MapboxGL.m | 39 +++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 platform/ios/MapboxGL.m diff --git a/gyp/platform-ios.gypi b/gyp/platform-ios.gypi index f70743118..142896c4e 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 c32915bc7..84c3f4542 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 000000000..b1cb44cbc --- /dev/null +++ b/platform/ios/MapboxGL.m @@ -0,0 +1,39 @@ +#import + +#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