[英]Facebook login setup failure
我已经多次浏览了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>
@凯文·卢阿
您需要在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)
}
当用户从应用程序登录时,将调用此方法。 尝试一下,让我知道它是否有效,否则将尝试帮助您解决其他问题。
由于最近的Xcode 10.1更新,这是Facebook SDK中的错误。 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
关键的变化是options
字典不再由String
类型作为键。 而是将键键入为UIApplication.OpenURLOptionsKey
,其定义如下:
// 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 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.