使用FB SDK和方法openActiveSessionWithReadPermissions,完成處理器似乎並不被調用時,該應用程序從Facebook的網頁或Facebook應用程序,我重新打開得到這個錯誤輸出:
FBSDKLog:從FBSessionStateCreated到FBSessionStateClosed FBSDKLog FBSession 無效過渡:FBSession過渡從FBSessionStateCreated到FBSessionStateCreatedOpening
語境
- 使用Facebook SDK 3.2.1
- 應用程序是專爲iOS 5.0及
- 測試模擬器上的iOS 5.1
- 測試的iPhone 4S使用的Xcode 4.6.1 ,運行iOS 6.1.2(不使用6.0社交框架,想測試實現5.0+)
- 更新最初爲iOS 3.0構建的應用程序和u唱一個老版本的sharekit,但現在已經更新了ARC和共享工具包的實現,我相信已經被註釋掉了 - 希望這個問題不是與舊的共享工具包功能衝突,不能在代碼 採取
步驟來解決搜索整個堆棧溢出
,發現提到類似的問題,但不是一個解決方案
- ios6 facebook integration login always FBSessionStateClosedLoginFailed never opens(我已經有布爾:應用程序中實現)
- Facebook iOS SDK 3.0 - session not open
- Facebook SDK 3.1 - Error validating access token
- 具有正確的應用程序捆綁在FB設置面板
- 具有正確的Facebook的應用程序ID是plist中
- 有無FB測井接通FBSettings setLoggingBehavior
具體細節:
這些是我採取的實施步驟t應用內的Facebook連接。
- 我採取的第一步是通過Facebook教程:https://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/。我得到了第一部分,認證部分按預期工作(我按照教程的指示構建了一個單獨的應用程序。)
- 然後我參加了我更新的應用程序的教程中相同的步驟,這並不工作
- 我再接着上https://developers.facebook.com/docs/howtos/login-with-facebook-using-ios-sdk/這是非常類似的教程)的指令(
- 我又跑了成問題
- 然後花了很多時間尋找解決方案,無法找到一個代碼
高層步驟:
- 我有我的FB方法設立的AppDelegate
- 在一個特定的視圖控制器我有一個按鈕,調用openSessionWithAllowLoginUI方法來啓動登錄過程
代碼
AppDelegate中。 m
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
// set up facebook logging
[FBSettings setLoggingBehavior:[NSSet setWithObjects:FBLoggingBehaviorFBRequests, FBLoggingBehaviorFBURLConnections, FBLoggingBehaviorAccessTokens, FBLoggingBehaviorSessionStateTransitions, nil]];
// Call the ACAccountStore method renewCredentialsForAccount, which will update the OS's understanding of the token state
ACAccountStore *accountStore;
ACAccountType *accountTypeFB;
if ((accountStore = [[ACAccountStore alloc] init]) &&
(accountTypeFB = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook])){
NSArray *fbAccounts = [accountStore accountsWithAccountType:accountTypeFB];
id account;
if (fbAccounts && [fbAccounts count] > 0 &&
(account = [fbAccounts objectAtIndex:0])){
[accountStore renewCredentialsForAccount:account completion:^(ACAccountCredentialRenewResult renewResult, NSError *error) {
//we don't actually need to inspect renewResult or error.
if (error){
}
}];
}
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// We need to properly handle activation of the application with regards to Facebook Login
// (e.g., returning from iOS 6.0 Login Dialog or from fast app switching).
NSLog(@"Calling app did become active");
[FBSession.activeSession handleDidBecomeActive];
}
/*
* Callback for session changes.
*/
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
NSLog(@"Session State Changed");
switch (state) {
case FBSessionStateOpen:
if (!error) {
// We have a valid session
NSLog(@"User session found");
}
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}
[[NSNotificationCenter defaultCenter]
postNotificationName:FBSessionStateChangedNotification
object:session];
if (error) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}
/*
* Opens a Facebook session and optionally shows the login UX.
*/
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
NSLog(@"Openning session with Facebook");
return [FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self sessionStateChanged:session
state:state
error:error];
}];
}
/*
* If we have a valid session at the time of openURL call, we handle
* Facebook transitions by passing the url argument to handleOpenURL
*/
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
NSLog(@"Calling open URL");
return [FBSession.activeSession handleOpenURL:url];
}
- (void) closeSession {
NSLog(@"Clossing Facebook Sessions");
[FBSession.activeSession closeAndClearTokenInformation];
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
NSLog(@"handleOpenUrl Called");
return [FBSession.activeSession handleOpenURL:url];
}
視圖控制器與按鈕
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
// Register for Facebook change notification
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(sessionStateChanged:)
name:FBSessionStateChangedNotification
object:nil];
}
- (IBAction)login:(id)sender {
ATIAppDelegate *myAppDelegate = (ATIAppDelegate *)[[UIApplication sharedApplication]delegate];
[myAppDelegate openSessionWithAllowLoginUI:YES];
}
我認爲這個問題可能呢?
- 它似乎可能是與令牌的東西?
- 或者也許是通知中心?
- 注意,在測試過程中,我一直打算和撤銷Facebook的應用程序到我的帳戶的訪問,然後嘗試再次登錄到應用程序,我看到這些已經引起問題與其他用戶
好吧,我弄明白了 - 這個問題與FB本身無關,應用程序(我正在更新其他人的代碼)在.plist中有一個設置 - '應用程序不在後臺運行'設置爲true。 這意味着,一旦應用程序從Facebook應用程序或Facebook移動網站重新啓動,它就沒有準備好處理下一步。 – drc
當我在幾個小時內使用stackoverflow時,我會添加這個作爲答案。 – drc
嘿DRC,我有同樣的錯誤,但我沒有看到「應用程序不在後臺運行」.plist中的任何地方。這是應用程序主.plist還是應用程序具有的附加.plist? – SasaT