我一直收到以下错误信息:
"Error Domain=com.facebook.sdk.login Code=308 "The operation couldn’t be completed. (com.facebook.sdk.login error 308.)""
当我尝试从我的设备登录 Facebook 时。
我的代码在模拟器上运行正常,但在实际设备上却不行。有人遇到过这个错误代码吗?如果需要,我很乐意分享代码。
我一直收到以下错误信息:
"Error Domain=com.facebook.sdk.login Code=308 "The operation couldn’t be completed. (com.facebook.sdk.login error 308.)""
当我尝试从我的设备登录 Facebook 时。
我的代码在模拟器上运行正常,但在实际设备上却不行。有人遇到过这个错误代码吗?如果需要,我很乐意分享代码。
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
设置打开网址
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)
对我来说,至少有一个解决方案,那就是不通过Xcode调试器在设备上运行。如果我在调试器外在设备上运行应用程序,则Facebook登录正常工作。如果我通过调试器在模拟器中运行应用程序,则Facebook登录也正常工作。
只有当我通过Xcode调试器在设备上运行应用程序时,每次都会出现"com.facebook.sdk.login error 308"。
您应该在能力标签页上启用钥匙串共享。
我曾经也遇到了完全相同的问题,通过修改Info.plist文件找到了解决方案。
我已经将所有可能的scheme添加到LSApplicationQueriesSchemes
中。
完整的列表如下:
<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>
Error Domain=com.facebook.sdk.login Code=308 "(null)"
我在FB的代码中进行了一些挖掘,似乎这只是一个权限问题。
FB使用钥匙串来存储登录期间的授权挑战。当返回时,它尝试从钥匙串获取值并失败。有关详细信息,请参见此SO答案。
安全性授权可以在配置文件之间更改,正如我们所知道的那样,保持配置文件、构建配置和设备/模拟器的一致性就像牵引猫一样困难。这可能解释了为什么人们会遇到如此不一致的行为。
因此,在生产环境中,一切都应该正常运作,如果在测试过程中出现问题,则需要仔细检查您的配置文件上的授权。
我曾经遇到过同样的问题,通过刷新系统凭据来解决了这个问题。
[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
}
}
}];
}];
如果您正在使用FBSDK 4.38,则在FBSDKLoginManager.m中解析challengeExpected存在错误。
我找到了rinat-enikeev的热修复方法:
https://github.com/facebook/facebook-sdk-swift/issues/286
只需要改变
NSString *challengeExpected = [self loadExpectedChallenge];
到
NSString *challengeExpected = [[self loadExpectedChallenge] stringByReplacingOccurrencesOfString:@"+" withString:@" "];
这对我解决了问题。