I am trying to present an UIAlertController
globally (from a place which is not a view controller) like this but my alert does not show up. I am testing my initial alert which is shown by reachability test in App Delegate after detecting no network. I can see launch image on my screen but alert does not show up. If I use UIAlertView
, everything looks good.
If you had encountered similar issue then please advise.
UIAlertController *alert = [UIAlertController alertControllerWithTitle:iTitle message:iMessage preferredStyle:UIAlertControllerStyleAlert];
id rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
if ([rootViewController isKindOfClass:[UINavigationController class]]) {
rootViewController = [((UINavigationController *)rootViewController).viewControllers objectAtIndex:0];
}
dispatch_async(dispatch_get_main_queue(), ^{
[rootViewController presentViewController:alert animated:YES completion:^{
[aBlockSelf alertPresented];
}];
});
EDIT:
Why am I showing it from AppDelegate
?
As I said, I am showing an alert to user as soon as I execute my reachability test. This test has to be performed from within AppDelegate
even before I load any view controller. So, I show a splash screen on my UIWindow
and I am expecting my alert to come on top of it.
Is my window set up correctly when I present the alert?
Yes, I am ensuring that I present alert controller post window is correctly set and that after below lines are executed!
[self.window addSubview:self.rootViewController.view];
[self.window makeKeyAndVisible];