2012-07-09 121 views
1

我目前正在尝试Facebook的单点登录功能,在我的移动应用程序。到目前为止,当我测试我的应用程序时,我可以访问Facebook身份验证对话框。但是当我点击确定按钮时,我的视图给了我一个黑屏。我想知道这是否是因为rootViewController的分配。相当奇怪的警告

enter image description here

在这行代码在我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; 
} 
+0

你确定'FbSSOTrialViewController * *实际*扩展了UIViewController吗? – 2012-07-09 03:47:01

+0

是的,请参阅编辑。 – Grauzten 2012-07-09 04:02:30

+0

好吧,接下来是一个挑剔的细节,可能会流光。请注意星号...在错误消息中,它可疑地从FbSSOTrialViewController丢失:'从FbSSOTrialViewController'分配给'UIViewController *'。我想知道是否这是一个错误在SO上,或者如果确实没有一个实际的指针,你认为它存在(那*是*错误是什么)......那么接下来要问怎么'self.FbSSOTrialVC '正在初始化。我怀疑你的问题在哪里。它看起来像被设置为Class对象,而不是指向实例的指针。 – 2012-07-09 04:07:25

回答

0

从我们的讨论其他的代码,它决定视图控制器在应用程序启动期间未正确实例化。我们确定,感兴趣的视图控制器是由一个故事板来了,所以建议代码变化如下:

// 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试用VC“(根据需要更改)。