2

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
Cœur
  • 37,241
  • 25
  • 195
  • 267
jqueryEnthusiast
  • 155
  • 1
  • 7
  • 17
  • Could you post your `MyGreatIOSAppAppDelegate.m`. You can just edit this post to do so. – Drew Mar 23 '12 at 18:36
  • Did you solve this problem? i am having the same problem if you did it will be nice if you publish the solution. – Hosni Jun 04 '12 at 12:42
  • Which version of Xcode are you using? Different versions have different project templates. Can you post `main.c` and your app delegate header as well? And a list of objects in your storyboard and `Info.plist`? – Jim Jul 28 '12 at 23:15
  • Dupes: http://stackoverflow.com/q/7520971/9530 http://stackoverflow.com/q/12784411/9530 http://stackoverflow.com/q/8706828/9530 http://stackoverflow.com/q/8190567/9530 http://stackoverflow.com/q/11515818/9530 and possibly more – Adam Rosenfield Mar 08 '13 at 20:42

2 Answers2

6

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

self.window.rootViewController = self.viewController;
jonkroll
  • 15,682
  • 4
  • 50
  • 43
  • Hi @jonkroll , I am using self.window.rootViewController = self.viewController; I am not sure but I am missing something 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. – jqueryEnthusiast Mar 23 '12 at 21:27
0

Make sure you set your window.rootviewcontroller = your _navigationviewcontroller. Like this: (this all happens in your AppDelegate.cs file)

public partial class AppDelegate : UIApplicationDelegate { // class-level declarations UIWindow _window; UINavigationController _navigationcontroller;

    //
    // This method is invoked when the application has loaded and is ready to run. In this 
    // method you should instantiate the window, load the UI into it and then make the window
    // visible.
    //
    // You have 17 seconds to return from this method, or iOS will terminate your application.
    //

    public override bool FinishedLaunching (UIApplication app, NSDictionary options)
    {
        // create a new window instance based on the screen size
        _window = new UIWindow (UIScreen.MainScreen.Bounds);

        // If you have defined a view, add it here:
        // window.AddSubview (navigationController.View);
        _navigationcontroller = new UINavigationController();
        _navigationcontroller.PushViewController(new SplashViewController(),false);
        **_window.RootViewController = _navigationcontroller;**

        // make the window visible



    _window.MakeKeyAndVisible ();

        return true;
    }
}

}