iphone - 应用程序窗口在应用程序启动结束时应该有一个 Root View Controller

标签 iphone ios facebook

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

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

我在 5.1 模拟器 (xcode 4.3.2) 上出现空白屏幕,控制台显示一条消息:

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

EDIT-1

感谢您的回复; 我在创建应用程序时选择了“单一 View 应用程序”模板。在 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

最佳答案

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

self.window.rootViewController = self.viewController;

关于iphone - 应用程序窗口在应用程序启动结束时应该有一个 Root View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9844626/

相关文章:

iphone - 如何用颜色填充图形区域

ios - 如果减少条形码扫描可以注册的元数据对象类型,它会获得更好的性能吗?

android - 是否可以生成一个 'share on Facebook' 链接以在 Android/iOS/移动设备上打开 native Facebook 应用程序而不是网络共享对话框?

iphone - Xcode 中缺少 iOS Devtools.Core Framework pbxcp?

iphone - 尝试以编程方式创建 rightBarButtonItem

iphone - 如何从 iOS 应用程序连接到 Oracle 数据库?

ios - 实际登录前Facebook "Not Logged In"错误

ios - 线程 1 : Signal Sigabrt error while creating a timer app

iphone - 访问子ViewController中的TabBarController变量

ios - 使用facebook登录IOS延迟查找用户的电子邮件