Fix alert presentation with UIAlertController

This commit is contained in:
Andreas Linde
2015-08-24 17:01:58 +02:00
parent e721bcfa19
commit 05de1686fa
6 changed files with 54 additions and 19 deletions

View File

@@ -275,7 +275,7 @@ static unsigned char kBITPNGEndChunk[4] = {0x49, 0x45, 0x4e, 0x44};
[alertController addAction:okAction];
[self showView:alertController];
[self showAlertController:alertController];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"

View File

@@ -1091,7 +1091,7 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
[alertController addAction:alwaysSendAction];
}
[self showView:alertController];
[self showAlertController:alertController];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"

View File

@@ -201,7 +201,7 @@
return navController;
}
- (void)showView:(UIViewController *)viewController {
- (UIViewController *)visibleWindowRootViewController {
// if we compile Crash only, then BITHockeyBaseViewController is not included
// in the headers and will cause a warning with the modulemap file
#if HOCKEYSDK_FEATURE_AUTHENTICATOR || HOCKEYSDK_FEATURE_UPDATES || HOCKEYSDK_FEATURE_FEEDBACK
@@ -222,14 +222,6 @@
parentViewController = parentViewController.presentedViewController;
}
// as per documentation this only works if called from within viewWillAppear: or viewDidAppear:
// in tests this also worked fine on iOS 6 and 7 but not on iOS 5 so we are still trying this
if ([parentViewController isBeingPresented]) {
BITHockeyLog(@"WARNING: There is already a view controller being presented onto the parentViewController. Delaying presenting the new view controller by 0.5s.");
[self performSelector:@selector(showView:) withObject:viewController afterDelay:0.5];
return;
}
// special addition to get rootViewController from three20 which has it's own controller handling
if (NSClassFromString(@"TTNavigator")) {
#pragma clang diagnostic push
@@ -241,6 +233,46 @@
#pragma clang diagnostic pop
}
return parentViewController;
#else
return nil;
#endif
}
- (void)showAlertController:(UIViewController *)alertController {
// if we compile Crash only, then BITHockeyBaseViewController is not included
// in the headers and will cause a warning with the modulemap file
#if HOCKEYSDK_FEATURE_AUTHENTICATOR || HOCKEYSDK_FEATURE_UPDATES || HOCKEYSDK_FEATURE_FEEDBACK
UIViewController *parentViewController = [self visibleWindowRootViewController];
// as per documentation this only works if called from within viewWillAppear: or viewDidAppear:
// in tests this also worked fine on iOS 6 and 7 but not on iOS 5 so we are still trying this
if ([parentViewController isBeingPresented]) {
BITHockeyLog(@"WARNING: There is already a view controller being presented onto the parentViewController. Delaying presenting the new view controller by 0.5s.");
[self performSelector:@selector(showAlertController:) withObject:alertController afterDelay:0.5];
return;
}
if (parentViewController) {
[parentViewController presentViewController:alertController animated:YES completion:nil];
}
#endif
}
- (void)showView:(UIViewController *)viewController {
// if we compile Crash only, then BITHockeyBaseViewController is not included
// in the headers and will cause a warning with the modulemap file
#if HOCKEYSDK_FEATURE_AUTHENTICATOR || HOCKEYSDK_FEATURE_UPDATES || HOCKEYSDK_FEATURE_FEEDBACK
UIViewController *parentViewController = [self visibleWindowRootViewController];
// as per documentation this only works if called from within viewWillAppear: or viewDidAppear:
// in tests this also worked fine on iOS 6 and 7 but not on iOS 5 so we are still trying this
if ([parentViewController isBeingPresented]) {
BITHockeyLog(@"WARNING: There is already a view controller being presented onto the parentViewController. Delaying presenting the new view controller by 0.5s.");
[self performSelector:@selector(showView:) withObject:viewController afterDelay:0.5];
return;
}
if (_navController != nil) _navController = nil;
_navController = [self customNavigationControllerWithRootViewController:viewController presentationStyle:_modalPresentationStyle];
@@ -260,6 +292,8 @@
} else {
// if not, we add a subview to the window. A bit hacky but should work in most circumstances.
// Also, we don't get a nice animation for free, but hey, this is for beta not production users ;)
UIWindow *visibleWindow = [self findVisibleWindow];
BITHockeyLog(@"INFO: No rootViewController found, using UIWindow-approach: %@", visibleWindow);
if ([viewController isKindOfClass:[BITHockeyBaseViewController class]])
[(BITHockeyBaseViewController *)viewController setModalAnimated:NO];

View File

@@ -71,6 +71,7 @@
// UI helpers
- (UIWindow *)findVisibleWindow;
- (UINavigationController *)customNavigationControllerWithRootViewController:(UIViewController *)viewController presentationStyle:(UIModalPresentationStyle)presentationStyle;
- (void)showAlertController:(UIViewController *)alertController;
- (void)showView:(UIViewController *)viewController;
#endif

View File

@@ -454,7 +454,7 @@
[alertController addAction:showAction];
[self showView:alertController];
[self showAlertController:alertController];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"

View File

@@ -103,7 +103,7 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
[alertController addAction:okAction];
[self showView:alertController];
[self showAlertController:alertController];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
@@ -576,7 +576,7 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
[alertController addAction:installAction];
[self showView:alertController];
[self showAlertController:alertController];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
@@ -640,7 +640,7 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
[alertController addAction:installAction];
}
[self showView:alertController];
[self showAlertController:alertController ];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
@@ -759,7 +759,7 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
[alertController addAction:checkAction];
}
[self showView:alertController];
[self showAlertController:alertController];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
@@ -903,7 +903,7 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
[alertController addAction:okAction];
[self showView:alertController];
[self showAlertController:alertController];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
@@ -1115,7 +1115,7 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
[alertController addAction:okAction];
[self showView:alertController];
[self showAlertController:alertController];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"