summaryrefslogtreecommitdiff
path: root/platform/ios/app
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-04-21 17:52:16 -0700
committerMinh Nguyễn <mxn@1ec5.org>2016-04-21 17:52:16 -0700
commite404eeae1bcd1edcbf4574bb14b3640d1d300038 (patch)
tree4843872a919e4d50b1269bdad7bef634dc6503a8 /platform/ios/app
parentab97e6012c209f5ab48731750c5286c1ca2b9b5e (diff)
downloadqtlocation-mapboxgl-e404eeae1bcd1edcbf4574bb14b3640d1d300038.tar.gz
[ios] Fixed crash on missing access token
Fixed a race condition in which the access token alert controller would fail to present because the view controller hadn’t yet entered the view hierarchy, plus a downstream crash caused by the access token being missing.
Diffstat (limited to 'platform/ios/app')
-rw-r--r--platform/ios/app/MBXViewController.m18
1 files changed, 14 insertions, 4 deletions
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m
index 2f4caf9939..d8bdc6d99e 100644
--- a/platform/ios/app/MBXViewController.m
+++ b/platform/ios/app/MBXViewController.m
@@ -54,12 +54,19 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(restoreState:) name:UIApplicationWillEnterForegroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveState:) name:UIApplicationWillTerminateNotification object:nil];
- self.styleIndex = -1;
- [self cycleStyles:self];
-
[self restoreState:nil];
+}
+
+- (void)viewDidAppear:(BOOL)animated
+{
+ [super viewDidAppear:animated];
- if ( ! [MGLAccountManager accessToken].length)
+ 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)
@@ -76,6 +83,9 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = {
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];