ios - Facebook 登录设置失败
问题描述
我已经多次阅读 Facebook“快速入门”指南,但似乎无法弄清楚导致此错误的原因。我正在尝试使用以下函数调用通过 FB 进行身份验证:
FBSDKLoginManager().logIn(withReadPermissions: ["public_profile", "email"], from: self) { (result, error) in
}
但是,我收到以下错误控制台输出:
-canOpenURL:URL 失败:“fbauth2:/” - 错误:“操作无法完成。(OSStatus 错误 -10814。)”
这是我的 AppDelegate 方法:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
return FBSDKApplicationDelegate.sharedInstance()!.application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
return FBSDKApplicationDelegate.sharedInstance()!.application(app, open: url, options: options)
}
Info.plist
按照快速入门指南的说明,我已将以下键/值添加到我的列表中:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb719997618357318</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>719997618357318</string>
<key>FacebookDisplayName</key>
<string>Test</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-share-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
解决方案
@Kelvin Lua
您需要在 AppDelegate 中实现此方法
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool{
return FBSDKApplicationDelegate.sharedInstance().application (
application,
open: url as URL!,
sourceApplication: sourceApplication,
annotation: annotation)
}
当用户从应用程序登录时,将调用此方法。试试吧,让我知道它是否有效,否则会尝试帮助您解决其他问题。
推荐阅读
- python - 为什么有些气象站坐标在尼日利亚边界之外?
- java - ImageView 动画翻译
- python - 在 Python 中将图像分配给 pandas 数据框的元素
- html - 如何修复 Vue.js 和 Spring Boot 应用程序中的 CORS 错误
- python-3.x - 创建一个所有元素最初设置为“无”的二维数组
- javascript - 为每个 @foreach 创建自己的脚本函数
- css - HostBinding 未绑定到 CSS 变量
- asp.net-mvc - Azure AD B2C 登录/设置有问题
- android-studio - 在 Android Studio 运行配置中更改检测类
- msbuild - MSBuild 选择部分 RecursiveDir