Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
#1225 - Initial setup of MapboxGL as a singleton object with access t…
Browse files Browse the repository at this point in the history
…oken
  • Loading branch information
bleege committed Apr 22, 2015
1 parent 1008787 commit 578d48b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions gyp/platform-ios.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 6 additions & 0 deletions include/mbgl/ios/MapboxGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
#import "MGLMapView.h"
#import "MGLTypes.h"
#import "MGLUserLocation.h"

@interface MapboxGL : NSObject

+ (void) sharedInstanceWithAccessToken:(NSString *)token;

@end
39 changes: 39 additions & 0 deletions platform/ios/MapboxGL.m
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

0 comments on commit 578d48b

Please sign in to comment.