我正在使用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
答案 0 :(得分:6)
检查应用程序委托的application:didFinishLaunchingWithOptions:
方法中是否有以下行:
self.window.rootViewController = self.viewController;
答案 1 :(得分:0)
确保设置window.rootviewcontroller =您的_navigationviewcontroller。像这样:(这一切都发生在你的AppDelegate.cs文件中)
public partial class AppDelegate:UIApplicationDelegate { //类级声明 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;
}
}
}