SDK更新到3.14后,原生Facebook登录停止工作

Mic*_*cky 26 facebook ios

更新:某种程度上,行为似乎已经改变.我不再收到错误消息,但本机登录仍然无法正常工作.相反,如果未安装Facebook应用程序,我将被重定向到Web对话框.Facebook是否删除了最后一个SDK的本机登录支持?我请求的权限是"public_profile","email"和"user_likes".我还尝试删除"user_likes"权限,因为它不是此处所述的基本权限的一部分:https://developers.facebook.com/docs/ios/ui-controls#iosintegration 仍然不会出现本机登录对话框!

我最近更新了我的iOS项目以使用Facebook SDK版本3.14.0(通过CocoaPods从3.13.0升级).我阅读了升级说明,并按照建议将权限"basic_info"更改为"public_profile".

如果我现在打电话

FBSession openActiveSessionWithReadPermissions:
                                   allowLoginUI:
                              completionHandler:
Run Code Online (Sandbox Code Playgroud)

它只能通过网络或Facebook App登录.如果我在操作系统设置中本机登录,则登录失败

Error Domain=com.facebook.sdk Code=2 "The operation couldn’t be completed. (com.facebook.sdk error 2.)"
Run Code Online (Sandbox Code Playgroud)

有没有人遇到类似的问题?本机登录不再以这种方式工作吗?或者是"更改"权限的问题?

问候K.

小智 56

我刚刚讨论了这个问题,这里有关于发生了什么以及如何修复我的应用程序的详细信息.

底线
由于新的登录过程,用户现在可以批准/拒绝每个请求的权限(本地ios集成登录不支持的内容),Facebook已经改变了sdk的默认登录行为,首先尝试Facebook快速应用程序切换然后退回在Web视图中,完全忽略任何ios系统级别的Facebook凭据.

这在升级指南(表3.13> 3.14)中注明:https://developers.facebook.com/docs/ios/upgrading

相关部分:
"默认登录行为已从FBSessionLoginBehaviorUseSystemAccountIfPresent更改为FBSessionLoginBehaviorWithFallbackToWebView."

那么该怎么办?
好吧,如果你不需要任何新东西,FBLikeControl等......,在3.14中引入,你可以降级到3.13.但是,如果你想/需要使用3.14n,那么在FBSession上有一个实例方法,它将FBSessionLoginBehavior作为参数:https://developers.facebook.com/docs/reference/ios/current/class/FBSession/#openWithBehavior: completionHandler:

我更新了我打开Facebook会话的方法主体:

    [FBSession openActiveSessionWithReadPermissions:@[@"email", @"user_location"]
                                       allowLoginUI:YES
                                  completionHandler:
                                          ^(FBSession *session, FBSessionState state, NSError *error) {
                                              [self sessionStateChanged:session state:state error:error];
                                          }
    ];

至:

    FBSessionStateHandler completionHandler = ^(FBSession *session, FBSessionState status, NSError *error) {
        [self sessionStateChanged:session state:status error:error];
    };

    if ([FBSession activeSession].state == FBSessionStateCreatedTokenLoaded) {
        // we have a cached token, so open the session
        [[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent
                  completionHandler:completionHandler];
    } else {
        [self clearAllUserInfo];
        // create a new facebook session
        FBSession *fbSession = [[FBSession alloc] initWithPermissions:@[@"email", @"user_location"]];
        [FBSession setActiveSession:fbSession];
        [fbSession openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent
                  completionHandler:completionHandler];
    }

注意:我的clearAllUserInfo方法包括以下行:

    [FBSession.activeSession closeAndClearTokenInformation];
    [FBSession renewSystemCredentials:^(ACAccountCredentialRenewResult result, NSError *error) {
        NSLog(@"%@", error);
    }];
    [FBSession setActiveSession:nil];

在理解会议上查看Facebook文档也值得一看:http: //developers.facebook.com/docs/facebook-login/ios/v2.0#sessions