[英]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.