我正在使用 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/