ios FBSDK 登录错误代码:Objective-C 中的 308

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30678712/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 06:13:57  来源:igfitidea点击:

FBSDK Login Error Code: 308 in Objective-C

iosfacebookparse-platformfacebook-sdk-4.0

提问by Jude Michael Murphy

I keep getting

我不断得到

"Error Domain=com.facebook.sdk.login Code=308 "The operation couldn't be completed. (com.facebook.sdk.login error 308.)""

"Error Domain=com.facebook.sdk.login Code=308 "操作无法完成。(com.facebook.sdk.login 错误 308。)""

upon trying to login with Facebook from my device.

尝试从我的设备登录 Facebook 时。

My code works on the simulator, but not on an actual device. Has anyone ran into this error code before? I'll be more than happy to share code upon request.

我的代码适用于模拟器,但不适用于实际设备。有没有人遇到过这个错误代码?我很乐意应要求共享代码。

采纳答案by user3633673

One solution, at least for me, is to not run on device via the Xcode debugger. If I run the app on device outside the debugger the Facebook login works fine. If I run the app in the sim via the debugger the Facebook login works fine.

至少对我而言,一种解决方案是不通过 Xcode 调试器在设备上运行。如果我在调试器之外的设备上运行该应用程序,则 Facebook 登录工作正常。如果我通过调试器在 sim 中运行该应用程序,则 Facebook 登录工作正常。

Only if I run the app on device via the Xcode debugger do I get the com.facebook.sdk.login error 308 every time.

只有当我通过 Xcode 调试器在设备上运行应用程序时,我才会每次都收到 com.facebook.sdk.login 错误 308。

回答by Suraj Pathak

The solution below works for iOS9 + running on Xcode 8, for Swift3.0

下面的解决方案适用于在 Xcode 8 上运行的 iOS9 +,适用于 Swift3.0

The steps are

步骤是

  1. Setup Facebook Launch
  1. 设置 Facebook 启动

FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

  1. Setup Open Url

    guard let source = options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String else { return false } let annotation = options[UIApplicationOpenURLOptionsAnnotationKey] as? String return FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: source, annotation: annotation)

  2. Fix Keychain permission issue as shown in the image below
  1. 设置打开网址

    guard let source = options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String else { return false } let annotation = options[UIApplicationOpenURLOptionsAnnotationKey] as? String return FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: source, annotation: annotation)

  2. 修复钥匙串权限问题,如下图所示

iOS 9 Keychain fix

iOS 9 钥匙串修复

回答by Di B.

You should enable Keychain Sharingon the Capabilitiestab.

您应该在功能选项卡上启用钥匙串共享

回答by Stas Zhukovskiy

I had exactly the same problem and was able to find the solution by modifying the Info.plist

我遇到了完全相同的问题,并且能够通过修改 Info.plist 找到解决方案

I've added all the possible schemes to LSApplicationQueriesSchemes

我已经添加了所有可能的方案 LSApplicationQueriesSchemes

The complete list looks like this:

完整列表如下所示:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fbapi</string>
    <string>fbapi20130214</string>
    <string>fbapi20130410</string>
    <string>fbapi20130702</string>
    <string>fbapi20131010</string>
    <string>fbapi20131219</string>
    <string>fbapi20140410</string>
    <string>fbapi20140116</string>
    <string>fbapi20150313</string>
    <string>fbapi20150629</string>
    <string>fbauth</string>
    <string>fbauth2</string>
    <string>fb</string>
    <string>fb-messenger-api20140430</string>
    <string>fb-messenger-platform-20150128</string>
    <string>fb-messenger-platform-20150218</string>
    <string>fb-messenger-platform-20150305</string>
    <string>fb-messenger-api</string>
    <string>fbshareextension</string>
</array>

回答by Geoff H

I'm getting the exact same thing FB SDK 4.6.0 Xcode 7.0 iOS9. All the setup & instructions on the facebook developer site were followed to the letter. None of the above solutions worked for me. I'm finding that the behaviour is worse when you're deploying to the device live and feeding back to the Xcode console while doing the login procedure. It's really pot luck if it actually logs you in or not. It seemsto behave in a more predictable way when you just re-launch your app cold after deployment. -Yes this is in fact the case!

我得到了完全相同的 FB SDK 4.6.0 Xcode 7.0 iOS9。facebook 开发者网站上的所有设置和说明都被严格遵守。以上解决方案都不适合我。我发现当您在执行登录过程时实时部署到设备并反馈到 Xcode 控制台时,行为会更糟。如果它真的让你登录,那真的是运气。当您在部署后冷启动应用程序时,它似乎以更可预测的方式运行。——是的,事实就是这样!

When it decides to fail to login it results in the following error:

当它决定登录失败时,会导致以下错误:

Error Domain=com.facebook.sdk.login Code=308 "(null)"

回答by Tai Le

My solution on Xcode7.1, Swift2.0

我在 Xcode7.1、Swift2.0 上的解决方案

Step 1. Clean your build folder: option+ command+ K

步骤1.清洁你的build文件夹:option+ command+K

or: Choose Product> Clean

或:选择Product>Clean

enter image description here

在此处输入图片说明

Step 2. Clean your derived data: Choose Window> Projects: enter image description here

步骤 2. 清理您的派生数据:选择Window> Projects在此处输入图片说明

and then choose Delete: enter image description here

然后选择Delete在此处输入图片说明

回答by edsancha

I had the same problem and fixed it refreshing the system credentials

我有同样的问题并修复它刷新系统凭据

[FBSDKLoginManager renewSystemCredentials:^(ACAccountCredentialRenewResult result, NSError *error) {

    [[[YourAuthManager manager] facebookLoginManager] logInWithReadPermissions:@[@"email"] fromViewController:nil handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {

        if (error) {
            // Handle error
        } else if (result.isCancelled) {
            // Handle cancellations
        } else {
            // If you ask for multiple permissions at once, you
            // should check if specific permissions missing
            if ([result.grantedPermissions containsObject:@"email"]) {
                // Do work
            }
        }
    }];
}];

This solution is less radical than reinstalling and you assure your users won't have to do it. My guess is that FBSDK 4.6 has some conflicts with iOS 9 system FB authentication credentials.

此解决方案不如重新安装那么彻底,您可以确保您的用户不必这样做。我的猜测是 FBSDK 4.6 与 iOS 9 系统 FB 身份验证凭据存在一些冲突。

Edited: After some time testing it kept happening, not as often as before but it was still an issue, so we downgraded to a previous version of FB SDK. Hopefully someone finds a better solution.

编辑:经过一段时间的测试后,它一直在发生,不像以前那么频繁,但仍然是一个问题,所以我们降级到以前版本的 FB SDK。希望有人找到更好的解决方案。

回答by kball

Did some digging around in FBs code and it looks like this is simply an entitlements issue.

在 FBs 代码中进行了一些挖掘,看起来这只是一个权利问题。

FB uses the keychain to store an authorization challenge during login. When returning it attempts to get the value from the keychain and fails. See this SO answerfor more info.

FB 使用钥匙串在登录期间存储授权质询。返回时,它尝试从钥匙串中获取值并失败。有关更多信息,请参阅此 SO 答案

Security entitlements can change between provisioning profiles, and as we all know, keeping our profiles and build configurations and devices/sims straight is like herding cats. This could explain why people experience such inconsistent behavior.

安全权限可以在配置文件之间更改,众所周知,保持我们的配置文件和构建配置以及设备/模拟卡的完整性就像放牧一样。这可以解释为什么人们会经历这种不一致的行为。

So it might be safe to assume that in a production environment, everything will work fine, and if things aren't working during testing then you need to double-check the entitlements on your provisioning profiles.

因此,可以安全地假设在生产环境中一切正常,如果在测试期间事情不正常,那么您需要仔细检查配置文件中的权利。

回答by AlexeyVMP

In my case it was fixed by updating to latest FB SDK. 4.10 at the moment.

在我的情况下,它是通过更新到最新的 FB SDK 来修复的。4.10 目前。

回答by SlickDev

Updating to the latest (4.11) FB SDK fixed this for me as well. Don't forget to clean your project after updating to see if it works for you!

更新到最新的 (4.11) FB SDK 也为我解决了这个问题。更新后不要忘记清理您的项目,看看它是否适合您!