Present view controller from app delegate

mikeholp picture mikeholp · Oct 18, 2013 · Viewed 38.9k times · Source

I'm attempting to present a view controller from the app delegate with this code:

- (void)interstitialViewControllerRequestSucceeded:(UIViewController *)interstitialViewController
{
    [self.window.rootViewController presentViewController:(UIViewController *)interstitialViewController animated:YES completion:NULL];
}

It will display the interstitial on the initial view controller but none of the others. I want it to display on every one attached to a navigation controller.

How can I modify this code to achieve that goal?

Answer

WrightsCS picture WrightsCS · Oct 18, 2013

You can also try:

[[[UIApplication sharedApplication] keyWindow] rootViewController]

How I use it:

#define ROOTVIEW [[[UIApplication sharedApplication] keyWindow] rootViewController]
[ROOTVIEW presentViewController:interstitialViewController animated:YES completion:^{}];