Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "Application windows are expected to have a root view controller" (iOS)

I've created a blank iPhone app project and would like to show a full-screen advertisement during app launch.

I tried to install the ad by following this guideline: https://github.com/mopub/mopub-ios-sdk/wiki/Interstitial-Integration-For-iOS

That's what I've done finally:

In ViewController.h

In ViewController.m

Actually all codes are just copied from the previous link.

However, an error shows when app runs:

Application windows are expected to have a root view controller at the end of application launch

I think this error may probably related to the loadView method, because if I remove the loadView method, the error disappeared.

In fact, this error seems common as it can be easily searched on the internet, but I don't know how loadView is related to it, and how can it be solved in my case.

Any solutions? Thanks a lot.

like image 718
Kit Ng Avatar asked Dec 26 '22 19:12

Kit Ng


1 Answers

You probably need to do this:

Add

#import "ViewController.h" 

to the top of AppDelegate.m

And in AppDelegate.m, your application:didFinishLaunchingWithOptions: method should have some code like this.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // ... Other code

    // Override point for customization after application launch.
    ViewController *viewController = [[ViewController alloc] init];

    self.window.rootViewController = viewController;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}
like image 114
Matt Tang Avatar answered Dec 28 '22 10:12

Matt Tang