summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-04-18 17:54:01 -0700
committerMinh Nguyễn <mxn@1ec5.org>2016-04-18 17:54:01 -0700
commit17a8079f3095128c0bd0f19f8b0961bcfd5a1eb2 (patch)
treead47547ad425011951b37160a986251bccc6ae51 /platform
parent6a6b51efbc2cb7042a86158b491e3a3e26851971 (diff)
downloadqtlocation-mapboxgl-17a8079f3095128c0bd0f19f8b0961bcfd5a1eb2.tar.gz
[ios] Prompt for access token in ios-bench
Prompt for an access token before starting benchmarking. /ref #4728
Diffstat (limited to 'platform')
-rw-r--r--platform/ios/benchmark/MBXBenchAppDelegate.h2
-rw-r--r--platform/ios/benchmark/MBXBenchAppDelegate.m26
-rw-r--r--platform/ios/benchmark/MBXBenchViewController.mm38
3 files changed, 51 insertions, 15 deletions
diff --git a/platform/ios/benchmark/MBXBenchAppDelegate.h b/platform/ios/benchmark/MBXBenchAppDelegate.h
index b8f6c2e641..e89add93fd 100644
--- a/platform/ios/benchmark/MBXBenchAppDelegate.h
+++ b/platform/ios/benchmark/MBXBenchAppDelegate.h
@@ -1,5 +1,7 @@
#import <UIKit/UIKit.h>
+extern NSString * const MBXMapboxAccessTokenDefaultsKey;
+
@interface MBXBenchAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
diff --git a/platform/ios/benchmark/MBXBenchAppDelegate.m b/platform/ios/benchmark/MBXBenchAppDelegate.m
index 5da6ccfcec..684c90d336 100644
--- a/platform/ios/benchmark/MBXBenchAppDelegate.m
+++ b/platform/ios/benchmark/MBXBenchAppDelegate.m
@@ -2,23 +2,23 @@
#import "MBXBenchViewController.h"
#import <Mapbox/Mapbox.h>
+NSString * const MBXMapboxAccessTokenDefaultsKey = @"MBXMapboxAccessToken";
+
@implementation MBXBenchAppDelegate
- (BOOL)application:(UIApplication*)application
didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
- 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.");
- } else {
+ if (![MGLAccountManager accessToken]) {
+ 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:MBXMapboxAccessTokenDefaultsKey];
+ } else {
+ // Try to retrieve from preferences, maybe we've stored them there previously and can reuse
+ // the token.
+ accessToken = [[NSUserDefaults standardUserDefaults] objectForKey:MBXMapboxAccessTokenDefaultsKey];
+ }
[MGLAccountManager setAccessToken:accessToken];
}
diff --git a/platform/ios/benchmark/MBXBenchViewController.mm b/platform/ios/benchmark/MBXBenchViewController.mm
index 5745a9748b..43e98d7ccd 100644
--- a/platform/ios/benchmark/MBXBenchViewController.mm
+++ b/platform/ios/benchmark/MBXBenchViewController.mm
@@ -1,5 +1,7 @@
#import "MBXBenchViewController.h"
+#import "MBXBenchAppDelegate.h"
+
#import <Mapbox/Mapbox.h>
#import "MGLMapView_Internal.h"
@@ -44,10 +46,42 @@
self.mapView.rotateEnabled = NO;
self.mapView.userInteractionEnabled = YES;
- [self startBenchmarkIteration];
-
[self.view addSubview:self.mapView];
+}
+- (void)viewDidAppear:(BOOL)animated
+{
+ [super viewDidAppear:animated];
+
+ if ([MGLAccountManager accessToken].length) {
+ [self startBenchmarkIteration];
+ } else {
+ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Access Token" message:@"Enter your Mapbox access token to load Mapbox-hosted tiles and styles:" preferredStyle:UIAlertControllerStyleAlert];
+ [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
+ textField.keyboardType = UIKeyboardTypeURL;
+ textField.autocorrectionType = UITextAutocorrectionTypeNo;
+ textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
+ }];
+
+ [alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
+ [self startBenchmarkIteration];
+ }]];
+ UIAlertAction *OKAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+ UITextField *textField = alertController.textFields.firstObject;
+ NSString *accessToken = textField.text;
+ [[NSUserDefaults standardUserDefaults] setObject:accessToken forKey:MBXMapboxAccessTokenDefaultsKey];
+ [MGLAccountManager setAccessToken:accessToken];
+ [self.mapView reloadStyle:self];
+
+ [self startBenchmarkIteration];
+ }];
+ [alertController addAction:OKAction];
+
+ if ([alertController respondsToSelector:@selector(setPreferredAction:)]) {
+ alertController.preferredAction = OKAction;
+ }
+ [self presentViewController:alertController animated:YES completion:nil];
+ }
}
size_t idx = 0;