首页 > 解决方案 > 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>

标签: iosswiftfacebook

解决方案


@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)
}

当用户从应用程序登录时,将调用此方法。试试吧,让我知道它是否有效,否则会尝试帮助您解决其他问题。


推荐阅读