Facebook login setup failure
我已经多次浏览了Facebook的"快速入门"指南,但似乎无法弄清楚是什么原因导致了该错误。 我正在尝试使用以下函数调用通过FB进行身份验证:
1 2 3 | FBSDKLoginManager().logIn(withReadPermissions: ["public_profile","email"], from: self) { (result, error) in } |
但是,我得到以下错误控制台输出:
-canOpenURL: failed for URL:"fbauth2:/" - error:"The operation couldn’t be completed. (OSStatus error -10814.)"
这是我的AppDelegate方法:
1 2 3 4 5 6 7 | 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) } |
如快速入门指南所述,我已将以下键/值添加到我的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <key>CFBundleURLTypes</key> <dict> <key>CFBundleURLSchemes</key> <string>fb719997618357318</string> </array> </dict> </array> <key>FacebookAppID</key> <string>719997618357318</string> <key>FacebookDisplayName</key> <string>Test</string> <key>LSApplicationQueriesSchemes</key> <string>fbapi</string> <string>fb-messenger-share-api</string> <string>fbauth2</string> <string>fbshareextension</string> </array> |
由于最近的Xcode 10.1更新,这是Facebook SDK中的错误。
1 2 3 4 5 6 7 8 | // 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 |
关键的变化是
1 2 3 4 5 | // Inside definition of `UIApplication` public struct OpenURLOptionsKey : Hashable, Equatable, RawRepresentable { public init(rawValue: String) } |
现在的解决方案是针对此线程讨论的Facebook SDK的特定版本:https://github.com/facebook/facebook-swift-sdk/issues/301。
@凯文·卢阿
您需要在AppDelegate中实现此方法
1 2 3 4 5 6 7 8 | 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) } |
当用户从应用程序登录时,将调用此方法。 请尝试一下,让我知道它是否有效,否则将尝试帮助您解决其他问题。