应用程序窗口应在应用程序启动结束时具有根视图控制器

jqu*_*ast 2 iphone facebook ios

我正在使用facebook iOS SDK安装教程:https://developers.facebook.com/docs/mobile/ios/build/

在第4步:添加注销到您的应用程序后,

我在5.1模拟器(xcode 4.3.2)上看到一个空白的白色屏幕,控制台显示一条消息:

应用程序窗口应在应用程序启动结束时具有根视图控制器

编辑-1

谢谢你的回复; 我在创建应用程序时选择了"单一视图应用程序"模板.在MainStoryBoard.storyboard中,我创建了一个对象并为其分配了MyGreatIOSAppAppDelegate类.将此对象的viewController出口拖放到View Controller.

这是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
Run Code Online (Sandbox Code Playgroud)

jon*_*oll 6

检查应用程序委托application:didFinishLaunchingWithOptions:方法中是否有以下行:

self.window.rootViewController = self.viewController;
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

14894 次

最近记录:

7 年,11 月 前