Difference between the legacy UIAlertView
and the new UIAlertController
is that the latter needs to be presented onto a specific viewcontroller wit
I found a workaround to find out which viewcontroller I can present the alert upon. I also posted the answer here:
@implementation UIViewController (visibleViewController)
- (UIViewController *)my_visibleViewController {
if ([self isKindOfClass:[UINavigationController class]]) {
// do not use method visibleViewController as the presentedViewController could beingDismissed
return [[(UINavigationController *)self topViewController] my_visibleViewController];
}
if ([self isKindOfClass:[UITabBarController class]]) {
return [[(UITabBarController *)self selectedViewController] my_visibleViewController];
}
if (self.presentedViewController == nil || self.presentedViewController.isBeingDismissed) {
return self;
}
return [self.presentedViewController my_visibleViewController];
}
@end
// To show a UIAlertController, present on the following viewcontroller:
UIViewController *visibleViewController = [[UIApplication sharedApplication].delegate.window.rootViewController my_visibleViewController];