summaryrefslogtreecommitdiff
path: root/platform/ios/app
diff options
context:
space:
mode:
Diffstat (limited to 'platform/ios/app')
-rw-r--r--platform/ios/app/MBXAppDelegate.h2
-rw-r--r--platform/ios/app/MBXAppDelegate.m20
-rw-r--r--platform/ios/app/MBXViewController.m37
-rwxr-xr-xplatform/ios/app/insert_access_token.sh17
4 files changed, 24 insertions, 52 deletions
diff --git a/platform/ios/app/MBXAppDelegate.h b/platform/ios/app/MBXAppDelegate.h
index 7ff321b6c7..e719cd9e6a 100644
--- a/platform/ios/app/MBXAppDelegate.h
+++ b/platform/ios/app/MBXAppDelegate.h
@@ -1,7 +1,5 @@
#import <UIKit/UIKit.h>
-extern NSString * const MBXMapboxAccessTokenDefaultsKey;
-
@interface MBXAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
diff --git a/platform/ios/app/MBXAppDelegate.m b/platform/ios/app/MBXAppDelegate.m
index 6abee91557..519c70766a 100644
--- a/platform/ios/app/MBXAppDelegate.m
+++ b/platform/ios/app/MBXAppDelegate.m
@@ -2,8 +2,6 @@
#import "MBXViewController.h"
#import <Mapbox/Mapbox.h>
-NSString * const MBXMapboxAccessTokenDefaultsKey = @"MBXMapboxAccessToken";
-
@interface MBXAppDelegate() <MGLMetricsManagerDelegate>
@end
@@ -12,25 +10,11 @@ NSString * const MBXMapboxAccessTokenDefaultsKey = @"MBXMapboxAccessToken";
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
- // Set access token, unless MGLAccountManager already read it in from Info.plist.
- 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];
#ifndef MGL_DISABLE_LOGGING
- [MGLLoggingConfiguration sharedConfiguration].loggingLevel = MGLLoggingLevelFault;
+ [MGLLoggingConfiguration sharedConfiguration].loggingLevel = MGLLoggingLevelFault;
#endif
- [MGLMetricsManager sharedManager].delegate = self;
- }
+ [MGLMetricsManager sharedManager].delegate = self;
return YES;
}
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m
index 1bd2b2f5b3..3335606f98 100644
--- a/platform/ios/app/MBXViewController.m
+++ b/platform/ios/app/MBXViewController.m
@@ -245,44 +245,17 @@ CLLocationCoordinate2D randomWorldCoordinate() {
[self restoreState:nil];
- self.debugLoggingEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"MGLMapboxMetricsDebugLoggingEnabled"];
- self.mapView.showsScale = YES;
- self.mapView.showsUserHeadingIndicator = YES;
- self.mapView.experimental_enableFrameRateMeasurement = YES;
- self.hudLabel.titleLabel.font = [UIFont monospacedDigitSystemFontOfSize:10 weight:UIFontWeightRegular];
-
if ([MGLAccountManager accessToken].length)
{
self.styleIndex = -1;
[self cycleStyles:self];
}
- 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:nil]];
- 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.styleIndex = -1;
- [self cycleStyles:self];
- [self.mapView reloadStyle:self];
- }];
- [alertController addAction:OKAction];
- alertController.preferredAction = OKAction;
- [self presentViewController:alertController animated:YES completion:nil];
- }
+ self.debugLoggingEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"MGLMapboxMetricsDebugLoggingEnabled"];
+ self.mapView.showsScale = YES;
+ self.mapView.showsUserHeadingIndicator = YES;
+ self.mapView.experimental_enableFrameRateMeasurement = YES;
+ self.hudLabel.titleLabel.font = [UIFont monospacedDigitSystemFontOfSize:10 weight:UIFontWeightRegular];
// Add fall-through single tap gesture recognizer. This will be called when
// the map view's tap recognizers fail.
diff --git a/platform/ios/app/insert_access_token.sh b/platform/ios/app/insert_access_token.sh
new file mode 100755
index 0000000000..3a3a776443
--- /dev/null
+++ b/platform/ios/app/insert_access_token.sh
@@ -0,0 +1,17 @@
+if [[ "$CI" ]]; then
+ echo "CI environment, access token not required"
+ exit 0
+else
+ echo "Inserting Mapbox access token..."
+ token_file=~/.mapbox
+ token_file2=~/mapbox
+ token="$(cat $token_file 2>/dev/null || cat $token_file2 2>/dev/null)"
+ if [ "$token" ]; then
+ plutil -replace MGLMapboxAccessToken -string $token "$TARGET_BUILD_DIR/$INFOPLIST_PATH"
+ echo "Token insertion successful"
+ else
+ echo \'error: Missing Mapbox access token\'
+ echo "error: Get an access token from <https://www.mapbox.com/studio/account/tokens/>, then create a new file at $token_file that contains the access token."
+ exit 1
+ fi
+fi