简体   繁体   English

Facebook登录设置失败

[英]Facebook login setup failure

I've gone through the Facebook "Quickstart" guide multiple times but can't seem to figure out what is causing this error. 我已经多次浏览了Facebook的“快速入门”指南,但似乎无法弄清楚是什么原因导致了该错误。 I'm trying to authenticate through FB using the following function call: 我正在尝试使用以下函数调用通过FB进行身份验证:

FBSDKLoginManager().logIn(withReadPermissions: ["public_profile", "email"], from: self) { (result, error) in

}

However, I'm getting the following error console output: 但是,我得到以下错误控制台输出:

-canOpenURL: failed for URL: "fbauth2:/" - error: "The operation couldn't be completed. (OSStatus error -10814.)" -canOpenURL:URL失败:“ fbauth2:/”-错误:“操作无法完成。(OSStatus错误-10814。)”

Here are my AppDelegate methods: 这是我的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)
}

I've added the following key/values to my Info.plist as told by the Quickstart guide: 如快速入门指南所述,我已将以下键/值添加到我的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 @凯文·卢阿

You need to implement this method in AppDelegate 您需要在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)
}

This method will be called when user logged in form the Application. 当用户从应用程序登录时,将调用此方法。 Just try it and let me know if it works or not else will try to help you out with something else. 尝试一下,让我知道它是否有效,否则将尝试帮助您解决其他问题。

This is a bug in the Facebook SDK due to the recent Xcode 10.1 update. 由于最近的Xcode 10.1更新,这是Facebook SDK中的错误。 The function signatures for UIApplicationDelegate have changed slightly: UIApplicationDelegate的功能签名已略有更改:

// before
func application(_ app: UIApplication,
                 open url: URL,
                 options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool
// before
func application(_ app: UIApplication,
                 open url: URL,
                 options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool

The key change is that the options dictionary is no longer keyed by String types. 关键的变化是options字典不再由String类型作为键。 Instead, the keys are typed as UIApplication.OpenURLOptionsKey , which have the following definition: 而是将键键入为UIApplication.OpenURLOptionsKey ,其定义如下:

// Inside definition of `UIApplication`
public struct OpenURLOptionsKey : Hashable, Equatable, RawRepresentable {

    public init(rawValue: String)
}

The solution right now is to target a specific version of the Facebook SDK discussed by this thread: https://github.com/facebook/facebook-swift-sdk/issues/301 . 现在的解决方案是针对此线程讨论的Facebook SDK的特定版本: https : //github.com/facebook/facebook-swift-sdk/issues/301

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM