简体   繁体   中英

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. I'm trying to authenticate through FB using the following function call:

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.)"

Here are my AppDelegate methods:

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:

<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

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. The function signatures for UIApplicationDelegate have changed slightly:

// 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. Instead, the keys are typed as UIApplication.OpenURLOptionsKey , which have the following definition:

// 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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