如何在 iOS10上使用 Facebook 的 iOSSDK

我正在尝试使用 Xcode 8构建一个使用 Swift 3登录 Facebook 的应用程序。当我切换回 iOS 模拟器9.3,它工作。在 iOS10中,我收到了这个错误:

""fbauth2:/" The operation couldn’t be completed. (OSStatus error -10814.)"

还有

Optional(Error Domain=com.facebook.sdk.login Code=308 "(null)")

有人有办法吗?

注一:

经过调试,这个问题是 FBSDK 不能更新 expect_challangesecurity.framework内部的函数 SecItemUpdate不工作。这是 IOS 10的问题

43275 次浏览

Error OSStatus -10814 occures when canOpenURL: can't find any application, that can open this URL (actually, Facebook trying to find their application by calling canOpenURL: with argument "fbauth2:/"). Printing happens inside of function, so you can't do anything with that. But if you will run your application on device with installed Facebook app, you will not see this error.

Error 308 occures because of the situation, when value, stored in keychain is not equal to value, that is stored in facebook completion parameters (for more information you can check -[FBSDKLoginManager completeAuthentication:expectChallenge:]).

It happens because Apple changed the way of working with keychain in iOS 10. To fix this issue you simply should go to Targets->Capabilities and enable keychain sharing (it enables access to keychain for your app): image

If you are using Xamarin (read this link for more information, thanks @dynamokaj):

Just make sure you enable the keychain access in Entitlements and select the entitlements for Simulator (Debug) builds too. By default this is not set.

In my case, the problem was Google Analytics. By default it seems it's adding its own view controller on top of the app's view controller. Setting "FirebaseAppDelegateProxyEnabled" to "NO" in {Your app}-Info.plist solved the problem.

The main reason why you're getting the following error,

canOpenURL: failed for URL: "fbauth2:/" - error: "The operation couldn’t be completed. (OSStatus error -10814.)

is that your iOS simulator does not have the Facebook Application installed. Until you install the application on your iOS simulator, you will continue to get the error. Try running your iOS application on a provisioned iOS device with Facebook installed and you will not see the error message again. Hope this helps!

Same problem was in my app, i checked many solution but did't works for me. I've fix this problem using below method.

Go to this Link Select Your App and configure your info.plist

import and add this code in your AppDelegate

import FBSDKCoreKit
import FBSDKLoginKit


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}


func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, options: options)
}

In my case, the fix was*:

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


// First, handle Facebook URL open request
if let fbSDKAppId = FBSDKSettings.appID(), url.scheme!.hasPrefix("fb\(fbSDKAppId)"), url.host == "authorize" {
let shouldOpen: Bool = FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String!, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
return shouldOpen
}


// After it, handle any other response (e.g. deep links)
handlerOtherUrls(url: url)
return true
}

*As recommended by @MoridinBG at Facebook SDK's Github page

This error can also be caused if you are using FBSDKCoreKit or FBSDKLoginKit version 4.39.0 . There was a bug in this version of the SDK. Upgrade to 4.39.1 or higher to fix it. Details here.

As a side note, other users mentioned that this error is seen if you don't have Facebook installed on the simulator. That is true, but the SDK is supposed to automatically fall back to the Web login method when the app is not installed. If that doesn't happen it may be caused by another issue such as missing/misconfigured values in your Info.plist (check LSApplicationQueriesSchemes) or missing methods on your AppDelegate.