2013-01-04 47 views
2
[FBSession openActiveSessionWithReadPermissions:nil 
            allowLoginUI:YES 
           completionHandler: 
^(FBSession *session, 
    FBSessionState state, NSError *error) { 
    [self sessionStateChanged:session state:state error:error]; 
}]; 

好了,經過一段時間的警報告訴我們說,我的應用程序試圖訪問Facebook和詢問是否它允許。Facebook的openActiveSessionWithReadPermission達到完成與狀態太快失敗

但是,該警報顯示在達到完成處理程序後。

當時狀態已經是FBSessionStateClosedLoginFailed。

我該怎麼辦?在模擬器中正常工作。

其實在臉書上的美味樣品也在我的iPhone上失敗。但我已經安裝了Facebook應用程序,並記錄在

+0

你一定錯過了什麼。我目前有同樣的問題,但我有其他應用程序正常工作..我試圖找出什麼已經失蹤。 Facebook的開發人員沒有全面的分步整合列表... – Zennichimaro

+0

在我的情況下,我錯過了[FBSession.activeSession handleOpenURL:url];在 - (BOOL)應用程序中:(UIApplication *)應用程序openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication註解:(id)註釋 – Zennichimaro

+0

Sharon,我遇到同樣的問題,特別是當用戶被撤銷時權限,而應用程序仍然打開。你做了什麼來解決你的問題? – SAHM

回答

1

Facebook的登錄清單:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { 
    return [FBSession.activeSession handleOpenURL:url]; 
} 


- (void)applicationDidBecomeActive:(UIApplication *)application { 
    // We need to properly handle activation of the application with regards to SSO 
    // (e.g., returning from iOS 6.0 authorization dialog or from fast app switching). 
    [FBSession.activeSession handleDidBecomeActive]; 
} 

- (void)applicationWillTerminate:(UIApplication *)application { 
    // if the app is going away, we close the session object; this is a good idea because 
    // things may be hanging off the session, that need releasing (completion block, etc.) and 
    // other components in the app may be awaiting close notification in order to do cleanup 
    [FBSession.activeSession close]; 
} 

在我sessionStateChanged:我這樣做

switch (state) { 
    case FBSessionStateOpen: 
     [[Facebook _instance] fbDialogLogin:session.accessToken expirationDate:session.expirationDate]; 
     break; 
    case FBSessionStateClosed: 
     [FBSession.activeSession closeAndClearTokenInformation]; 
     break; 
    case FBSessionStateClosedLoginFailed: 
     break; 
    default: 
     NSLog(@"FBSessionStateUnknown: %d", state); 
     break; 
} 

不要忘記,以確保您的FacebookAppID和BundleID與您在Facebook開發人員儀表板中創建的相同!

2

我通過轉到設置並在我的應用上啓用了Facebook來解決此問題。不知道爲什麼它首先出現。