diff options
author | Brad Leege <bleege@gmail.com> | 2015-05-05 13:00:25 -0500 |
---|---|---|
committer | Brad Leege <bleege@gmail.com> | 2015-05-05 13:00:25 -0500 |
commit | acd27fc386ba413fbec4cac75d4407eb77712883 (patch) | |
tree | c227dd491369473ad25f0faf4018921df5f89d1c /ios | |
parent | 97fe50f35dbaa653fce44aa2918ba20b65c6b704 (diff) | |
parent | 804c092c81c01a4ba9bc25654c30f5f285e6eb54 (diff) | |
download | qtlocation-mapboxgl-acd27fc386ba413fbec4cac75d4407eb77712883.tar.gz |
Merge pull request #1329 from mapbox/1225-start-token
MapboxGL Startup Infrastructure
Diffstat (limited to 'ios')
-rw-r--r-- | ios/app/MBXAppDelegate.m | 18 | ||||
-rw-r--r-- | ios/app/MBXViewController.mm | 15 |
2 files changed, 19 insertions, 14 deletions
diff --git a/ios/app/MBXAppDelegate.m b/ios/app/MBXAppDelegate.m index f2ef69ec63..90c552aba0 100644 --- a/ios/app/MBXAppDelegate.m +++ b/ios/app/MBXAppDelegate.m @@ -1,11 +1,29 @@ #import "MBXAppDelegate.h" #import "MBXViewController.h" +#import <mbgl/ios/MapboxGL.h> +#import <mbgl/ios/MGLAccountManager.h> #import <mbgl/ios/MGLMapboxEvents.h> @implementation MBXAppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // Set Access Token + NSString *accessToken = [[NSProcessInfo processInfo] environment][@"MAPBOX_ACCESS_TOKEN"]; + if (accessToken) { + // Store to preferences so that we can launch the app later on without having to specify + // token. + [[NSUserDefaults standardUserDefaults] setObject:accessToken forKey:@"access_token"]; + } else { + // Try to retrieve from preferences, maybe we've stored them there previously and can reuse + // the token. + accessToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"access_token"]; + } + if ( ! accessToken) NSLog(@"No access token set. Mapbox vector tiles won't work."); + + // Start Mapbox GL SDK + [MGLAccountManager setAccessToken:accessToken]; + self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[MBXViewController new]]; [self.window makeKeyAndVisible]; diff --git a/ios/app/MBXViewController.mm b/ios/app/MBXViewController.mm index 98c8e016db..eb77a2ec80 100644 --- a/ios/app/MBXViewController.mm +++ b/ios/app/MBXViewController.mm @@ -52,20 +52,7 @@ mbgl::Settings_NSUserDefaults *settings = nullptr; { [super viewDidLoad]; - NSString *accessToken = [[NSProcessInfo processInfo] environment][@"MAPBOX_ACCESS_TOKEN"]; - if (accessToken) { - // Store to preferences so that we can launch the app later on without having to specify - // token. - [[NSUserDefaults standardUserDefaults] setObject:accessToken forKey:@"access_token"]; - } else { - // Try to retrieve from preferences, maybe we've stored them there previously and can reuse - // the token. - accessToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"access_token"]; - } - - if ( ! accessToken) NSLog(@"No access token set. Mapbox vector tiles won't work."); - - self.mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds accessToken:accessToken]; + self.mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds]; self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; self.mapView.showsUserLocation = YES; self.mapView.delegate = self; |