原生Facebook登录在SDK更新到3.14后停止工作 [英] Native Facebook Login stopped working after SDK update to 3.14

查看:100
本文介绍了原生Facebook登录在SDK更新到3.14后停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:不知怎么行为似乎已经改变了。我没有收到错误信息,但本机登录仍然不起作用。而是如果没有安装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(从3.13.0通过CocoaPods升级)。我阅读升级说明,并将建议的basic_info权限更改为public_profile。



如果我现在调用



pre> FBSession openActiveSessionWithReadPermissions:
allowLoginUI:
completionHandler:

它只能通过网络或Facebook应用程序登录。如果我在操作系统设置中登录本地,则登录失败,

  Error Domain = com.facebook.sdk Code = 2操作无法完成(com.facebook.sdk error 2.)

有没有人经历过类似的问题?本地登录工作不是这样吗?或者是更改权限的问题?



Regards
K

解决方案

我也刚刚遇到这个问题,这里是发生了什么的细节如何修复我的应用程序。



底线

由于用户现在可以批准/拒绝的新登录过程每个请求的权限(本机ios集成登录不支持的东西),Facebook已经更改了sdk的默认登录行为,首先尝试使用Facebook快速应用开关&然后回到网络视图,完全忽略任何ios系统级别的Facebook凭据。



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



相关部分:

默认登录行为已从FBSessionLoginBehaviorUseSystemAccountIfPresent更改为FBSessionLoginBehaviorWithFallbackToWebView。



那么该怎么办? / strong>

嗯,如果你不需要任何新的东西,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状态,NSError *错误){
[self sessionStateChanged:session state:state error :错误];
}
];

to:

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

if([FBSession activeSession] .state == FBSessionStateCreatedTokenLoaded){
//我们有一个缓存的令牌,所以打开会话
[[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent
completionHandler:completionHandler];
} else {
[self clearAllUserInfo];
//创建一个新的facebook会话
FBSession * fbSession = [[FBSession alloc] initWithPermissions:@ [@email,@user_location]];
[FBSession setActiveSession:fbSession];
[fbSession openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent
completionHandler:completionHandler];
}

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

 
[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


Update: Somehow the behaviour seems to have changed. I don't get the error message any more but the native login still does not work. Instead I am redirected to the web dialog if the Facebook app is not installed. Did Facebook remove the native login support for the last SDK? The permissions I request were "public_profile", "email" and "user_likes". I also tried removing the "user_likes" permission, as it is not part of the basic permissions as stated here: https://developers.facebook.com/docs/ios/ui-controls#iosintegration Still the native login dialog does not appear!

I recently updated my iOS Project to use the Facebook SDK version 3.14.0 (upgraded from 3.13.0 via CocoaPods). I read the upgrade notes and changed the permission "basic_info" to "public_profile" as recommended.

If I now call

FBSession openActiveSessionWithReadPermissions:
                                   allowLoginUI:
                              completionHandler:

it only works via the web or Facebook App login. If I login natively in the OS settings, the login fails with

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

Has anyone experienced similar problems? Doesn't the native login work anymore this way? Or is it a problem with the "changed" permissions?

Regards K

解决方案

I just ran to this issue also, here's the details on what has happened & how I fixed my app.

Bottom line
Due to the new login process wherein users can now approve / deny each requested permission (something not supported by the native ios integrated login), Facebook has changed the sdk's default login behavior to first try the Facebook fast app switch & then fall back on the web view, completely ignoring any ios system level Facebook credentials.

This is noted in the upgrade guide (form 3.13 > 3.14) here: https://developers.facebook.com/docs/ios/upgrading

Relevant portion:
"The default login behavior has changed from FBSessionLoginBehaviorUseSystemAccountIfPresent to FBSessionLoginBehaviorWithFallbackToWebView."

So what to do?
Well, if you don't need any of the new things, FBLikeControl etc..., that were introduced in 3.14, you could just downgrade to 3.13. However, if you want/need to use 3.14n there's an instance method on FBSession that takes the FBSessionLoginBehavior as a parameter: https://developers.facebook.com/docs/reference/ios/current/class/FBSession/#openWithBehavior:completionHandler:

I updated the body of my method for opening a Facebook session from:

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

to:

    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];
    }

NOTE: my clearAllUserInfo method includes the following lines:

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

It's also worth checking out the Facebook documentation on understanding sessions: http://developers.facebook.com/docs/facebook-login/ios/v2.0#sessions

这篇关于原生Facebook登录在SDK更新到3.14后停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆