From 14122dab54546137fe68331268190a4c08774b04 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 20 Feb 2018 13:46:21 -0500 Subject: [PATCH] Fix the storage failure alert. --- Signal/src/AppDelegate.m | 92 +++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 40 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index c836672bf..b76a0891d 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -274,7 +274,10 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Show the launch screen until the async database view registrations are complete. - self.window.rootViewController = [self loadingRootViewController]; + // + // Note: we void using loadingRootViewController, since it will indirectly try to + // instantiate primary storage, which will fail. + self.window.rootViewController = [self loadingRootViewControllerWithShowUpgradeWarning:NO]; [self.window makeKeyAndVisible]; @@ -358,9 +361,6 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; - (UIViewController *)loadingRootViewController { - UIViewController *viewController = - [[UIStoryboard storyboardWithName:@"Launch Screen" bundle:nil] instantiateInitialViewController]; - NSString *lastLaunchedAppVersion = AppVersion.instance.lastAppVersion; NSString *lastCompletedLaunchAppVersion = AppVersion.instance.lastCompletedLaunchAppVersion; // Every time we change or add a database view in such a way that @@ -373,44 +373,56 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; [VersionMigrations isVersion:lastCompletedLaunchAppVersion lessThan:kLastVersionWithDatabaseViewChange])); DDLogInfo(@"%@ mayNeedUpgrade: %d", self.logTag, mayNeedUpgrade); - if (mayNeedUpgrade) { - UIView *rootView = viewController.view; - UIImageView *iconView = nil; - for (UIView *subview in viewController.view.subviews) { - if ([subview isKindOfClass:[UIImageView class]]) { - iconView = (UIImageView *)subview; - break; - } - } - if (!iconView) { - OWSFail(@"Database view registration overlay has unexpected contents."); - } else { - UILabel *bottomLabel = [UILabel new]; - bottomLabel.text = NSLocalizedString( - @"DATABASE_VIEW_OVERLAY_SUBTITLE", @"Subtitle shown while the app is updating its database."); - bottomLabel.font = [UIFont ows_mediumFontWithSize:16.f]; - bottomLabel.textColor = [UIColor whiteColor]; - bottomLabel.numberOfLines = 0; - bottomLabel.lineBreakMode = NSLineBreakByWordWrapping; - bottomLabel.textAlignment = NSTextAlignmentCenter; - [rootView addSubview:bottomLabel]; - - UILabel *topLabel = [UILabel new]; - topLabel.text = NSLocalizedString( - @"DATABASE_VIEW_OVERLAY_TITLE", @"Title shown while the app is updating its database."); - topLabel.font = [UIFont ows_mediumFontWithSize:20.f]; - topLabel.textColor = [UIColor whiteColor]; - topLabel.numberOfLines = 0; - topLabel.lineBreakMode = NSLineBreakByWordWrapping; - topLabel.textAlignment = NSTextAlignmentCenter; - [rootView addSubview:topLabel]; - - [bottomLabel autoPinWidthToSuperviewWithMargin:20.f]; - [topLabel autoPinWidthToSuperviewWithMargin:20.f]; - [bottomLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:topLabel withOffset:10.f]; - [iconView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:bottomLabel withOffset:40.f]; + + return [self loadingRootViewControllerWithShowUpgradeWarning:mayNeedUpgrade]; +} + +- (UIViewController *)loadingRootViewControllerWithShowUpgradeWarning:(BOOL)showUpgradeWarning +{ + UIViewController *viewController = + [[UIStoryboard storyboardWithName:@"Launch Screen" bundle:nil] instantiateInitialViewController]; + + if (!showUpgradeWarning) { + return viewController; + } + + UIView *rootView = viewController.view; + UIImageView *iconView = nil; + for (UIView *subview in viewController.view.subviews) { + if ([subview isKindOfClass:[UIImageView class]]) { + iconView = (UIImageView *)subview; + break; } } + if (!iconView) { + OWSFail(@"Database view registration overlay has unexpected contents."); + return viewController; + } + + UILabel *bottomLabel = [UILabel new]; + bottomLabel.text = NSLocalizedString( + @"DATABASE_VIEW_OVERLAY_SUBTITLE", @"Subtitle shown while the app is updating its database."); + bottomLabel.font = [UIFont ows_mediumFontWithSize:16.f]; + bottomLabel.textColor = [UIColor whiteColor]; + bottomLabel.numberOfLines = 0; + bottomLabel.lineBreakMode = NSLineBreakByWordWrapping; + bottomLabel.textAlignment = NSTextAlignmentCenter; + [rootView addSubview:bottomLabel]; + + UILabel *topLabel = [UILabel new]; + topLabel.text + = NSLocalizedString(@"DATABASE_VIEW_OVERLAY_TITLE", @"Title shown while the app is updating its database."); + topLabel.font = [UIFont ows_mediumFontWithSize:20.f]; + topLabel.textColor = [UIColor whiteColor]; + topLabel.numberOfLines = 0; + topLabel.lineBreakMode = NSLineBreakByWordWrapping; + topLabel.textAlignment = NSTextAlignmentCenter; + [rootView addSubview:topLabel]; + + [bottomLabel autoPinWidthToSuperviewWithMargin:20.f]; + [topLabel autoPinWidthToSuperviewWithMargin:20.f]; + [bottomLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:topLabel withOffset:10.f]; + [iconView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:bottomLabel withOffset:40.f]; return viewController; }