非常奇怪的警告

时间:2012-07-09 03:41:01

标签: ios facebook uiapplicationdelegate

我目前正在手机应用中试用Facebook的单点登录功能。到目前为止,我可以在测试我的应用时访问Facebook Auth Dialog。但是当我在授权应用程序时单击“确定”按钮时,我的视图会给我一个黑屏。我想知道这是否是因为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;
}

1 个答案:

答案 0 :(得分: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”(根据需要进行更改)。