diff options
author | Brad Leege <bleege@gmail.com> | 2015-05-05 11:50:01 -0500 |
---|---|---|
committer | Brad Leege <bleege@gmail.com> | 2015-05-05 11:50:01 -0500 |
commit | 804c092c81c01a4ba9bc25654c30f5f285e6eb54 (patch) | |
tree | 7f23bb3c49d3a1933a98e78e850d22cc77f20499 | |
parent | 4ce4e979ff85f8fc135fccf675c6a5e8939cdd66 (diff) | |
download | qtlocation-mapboxgl-804c092c81c01a4ba9bc25654c30f5f285e6eb54.tar.gz |
#1225 - Simplifying MGLAccountManager for initial setup and access to AccessToken
-rw-r--r-- | include/mbgl/ios/MGLAccountManager.h | 4 | ||||
-rw-r--r-- | ios/app/MBXAppDelegate.m | 3 | ||||
-rw-r--r-- | platform/ios/MGLAccountManager.m | 23 | ||||
-rw-r--r-- | platform/ios/MGLMapView.mm | 2 |
4 files changed, 18 insertions, 14 deletions
diff --git a/include/mbgl/ios/MGLAccountManager.h b/include/mbgl/ios/MGLAccountManager.h index 569a01cc56..c1b7406b9e 100644 --- a/include/mbgl/ios/MGLAccountManager.h +++ b/include/mbgl/ios/MGLAccountManager.h @@ -1,6 +1,6 @@ @interface MGLAccountManager : NSObject -+ (instancetype) sharedInstanceWithAccessToken:(NSString *)token; -+ (NSString *) sharedAccessToken; ++ (void) setAccessToken:(NSString *) accessToken; ++ (NSString *) accessToken; @end
\ No newline at end of file diff --git a/ios/app/MBXAppDelegate.m b/ios/app/MBXAppDelegate.m index 0a81e83fb8..90c552aba0 100644 --- a/ios/app/MBXAppDelegate.m +++ b/ios/app/MBXAppDelegate.m @@ -21,7 +21,8 @@ } if ( ! accessToken) NSLog(@"No access token set. Mapbox vector tiles won't work."); - [MGLAccountManager sharedInstanceWithAccessToken:accessToken]; + // Start Mapbox GL SDK + [MGLAccountManager setAccessToken:accessToken]; self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[MBXViewController new]]; diff --git a/platform/ios/MGLAccountManager.m b/platform/ios/MGLAccountManager.m index 22608f94c8..b1a80fd6a7 100644 --- a/platform/ios/MGLAccountManager.m +++ b/platform/ios/MGLAccountManager.m @@ -15,17 +15,14 @@ static MGLAccountManager *_sharedManager; -// Can be called from any thread. Called implicitly from any -// public class convenience methods. +// Can be called from any thread. // -+ (instancetype) sharedInstanceWithAccessToken:(NSString *)token { ++ (instancetype) sharedInstance { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ if ( ! NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent) { void (^setupBlock)() = ^{ _sharedManager = [[self alloc] init]; - _sharedManager.accessToken = token; - [MGLMapboxEvents setToken:token]; }; if ( ! [[NSThread currentThread] isMainThread]) { dispatch_sync(dispatch_get_main_queue(), ^{ @@ -40,11 +37,17 @@ static MGLAccountManager *_sharedManager; return _sharedManager; } -+ (NSString *) sharedAccessToken { - if (_sharedManager) { - return _sharedManager.accessToken; - } - return nil; ++ (void) setAccessToken:(NSString *) accessToken { + [[MGLAccountManager sharedInstance] setAccessToken:accessToken]; + + // Update MGLMapboxEvents + // NOTE: This is (likely) the initial setup of MGLMapboxEvents + [MGLMapboxEvents setToken:accessToken]; +} + ++ (NSString *) accessToken { + return [MGLAccountManager sharedInstance].accessToken; } + @end
\ No newline at end of file diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index 6e4b94e2fa..01ef0835ea 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -110,7 +110,7 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration) if (self && [self commonInit]) { self.styleURL = nil; - self.accessToken = [MGLAccountManager sharedAccessToken]; + self.accessToken = [MGLAccountManager accessToken]; return self; } |