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

15,051

Check that you have the following line in your application delegate's application:didFinishLaunchingWithOptions: method:

self.window.rootViewController = self.viewController;
Share:
15,051
jqueryEnthusiast
Author by

jqueryEnthusiast

Updated on July 18, 2022

Comments

  • jqueryEnthusiast
    jqueryEnthusiast almost 2 years

    I am using the facebook iOS SDK setup tutorial: https://developers.facebook.com/docs/mobile/ios/build/

    After Step 4: Adding Log Out to your App,

    I get a blank white screen on the 5.1 simulator (xcode 4.3.2) and the console shows a message:

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

    EDIT-1

    Thanks for your responses; I chose a "Single View Application" template while creating the app. In the MainStoryBoard.storyboard, I created an object and assigned the MyGreatIOSAppAppDelegate class to it. Drag-dropped the viewController outlet of this object to the View Controller.

    here is the code in MyGreatIOSAppAppDelegate.m

    #import "MyGreatIOSAppAppDelegate.h"
    #import "xxxViewController.h"
    
    @implementation IJSAppDelegate
    
    @synthesize window = _window;
    @synthesize viewController = _viewController;
    @synthesize facebook;
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // Override point for customization after application launch.
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
    
        // Add the logout button
        UIButton *logoutButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        logoutButton.frame = CGRectMake(40, 40, 200, 40);
        [logoutButton setTitle:@"Log Out" forState:UIControlStateNormal];
        [logoutButton addTarget:self action:@selector(logoutButtonClicked)
               forControlEvents:UIControlEventTouchUpInside];
        [self.viewController.view addSubview:logoutButton];    
    
        facebook = [[Facebook alloc] initWithAppId:@"id" andDelegate:self];
    
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        if ([defaults objectForKey:@"FBAccessTokenKey"] 
            && [defaults objectForKey:@"FBExpirationDateKey"]) {
            facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
            facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
        }
        if (![facebook isSessionValid]) {
            [facebook authorize:nil];
        }
        return YES;
    }
    
    
    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
      sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
        return [facebook handleOpenURL:url]; 
    }
    
    - (void)fbDidLogin {
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
        [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
        [defaults synchronize];
    }
    
    // Method that gets called when the logout button is pressed
    - (void) logoutButtonClicked:(id)sender {
        [facebook logout];
    }
    
    - (void) fbDidLogout {
        // Remove saved authorization information if it exists
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        if ([defaults objectForKey:@"FBAccessTokenKey"]) {
            [defaults removeObjectForKey:@"FBAccessTokenKey"];
            [defaults removeObjectForKey:@"FBExpirationDateKey"];
            [defaults synchronize];
        }
    }
    
    @end