1

我目前正在我的移动应用程序中尝试 Facebook 的单点登录功能。到目前为止,我可以在测试我的应用程序时访问 Facebook Auth Dialog。但是当我在授权应用程序时单击“确定”按钮时,我的视图给了我一个黑屏。我想知道这是否是因为rootViewController.

在此处输入图像描述

在我的这行代码中FbSSOTrialDelegate.m

self.window.rootViewController = self.FbSSOTrialVC;

我收到一条警告消息Incompatible pointer types assigning to 'UIViewController *' from 'FbSSOTrialViewController *',并且在我的控制台中也有此日志:

2012-07-09 11:17:04.798 FbSSOTrial[976:f803] Application windows are expected to have a root view controller at the end of application launch

我说这很奇怪,因为我确定这FbSSOTrialVCUIViewController

请告诉我为什么会发生这种情况。以下是 FbSSOTrialViewController.h 的其他代码

#import <UIKit/UIKit.h>

@interface FbSSOTrialViewController : UIViewController

@end

和 appDelegate

FbSSOTrialDelegate.h

#import <UIKit/UIKit.h>
#import "FBConnect.h"

@class FbSSOTrialViewController;


@interface FbSSOTrialAppDelegate : NSObject <UIApplicationDelegate, FBSessionDelegate>
{
    Facebook *facebook;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet FbSSOTrialViewController *FbSSOTrialVC;
@property (nonatomic, retain) Facebook *facebook;

@end

FbSSOTrialDelegate.m

#import "FbSSOTrialAppDelegate.h"

@implementation FbSSOTrialAppDelegate

@synthesize window = _window;
@synthesize facebook = _facebook;
@synthesize FbSSOTrialVC = _FbSSOTrialVC;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    NSString *FbAppId = @"MY_APP_ID";

    self.window.rootViewController = self.FbSSOTrialVC;
    [self.window makeKeyAndVisible];

    self.facebook = [[Facebook alloc] initWithAppId:FbAppId andDelegate:self];

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) {
        self.facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
        self.facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
    }

    if (![self.facebook isSessionValid]) {
        [self.facebook authorize:nil];
    }

    return YES;
}
4

1 回答 1

0

根据我们的讨论,我们确定视图控制器在应用程序启动期间没有被正确实例化。我们确定感兴趣的 ViewController 来自故事板,因此建议的代码更改如下:

// remove this
// self.window.rootViewController = self.FbSSOTrialVC;

// and replace it with:
self.FbSSOTrialVC = [self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"Fb SSO Trial VC"];
self.window.rootViewController = self.FbSSOTrialVC;

请注意,这要求在情节提要中,感兴趣的 ViewController 应具有标识符“Fb SSO Trial VC”(根据需要更改这些)。

于 2012-07-09T07:01:56.447 回答