如何在 iOS 10 上使用 Facebook iOS SDK

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38689631/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 09:48:02  来源:igfitidea点击:

How to use Facebook iOS SDK on iOS 10

iosswiftfacebook-ios-sdkios10

提问by trquoccuong

I am trying to use Xcode 8 to build a app with Facebook login using Swift 3. When I switch back iOS Simulator 9.3, it works. In iOS 10, I receive this error:

我正在尝试使用 Xcode 8 构建一个使用 Swift 3 登录 Facebook 的应用程序。当我切换回 iOS Simulator 9.3 时,它可以工作。在 iOS 10 中,我收到此错误:

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

and

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

Anyone have solution for this?

有人对此有解决方案吗?

Note 1 :

注 1:

After debugging, this problem is FBSDK cant update expect_challange. Function SecItemUpdateinside security.frameworknot work. This is a problem of IOS 10

经过调试,这个问题是FBSDK无法更新expect_challangeSecItemUpdate里面的功能security.framework不行。这是IOS 10的问题

回答by Roman Ermolov

Error OSStatus -10814occures 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.

canOpenURL:找不到任何可以打开此 URL 的应用程序时,出现 OSStatus-10814错误(实际上,Facebook 试图通过canOpenURL:使用参数“fbauth2:/”调用来找到他们的应用程序)。打印发生在函数内部,所以你不能用它做任何事情。但是,如果您将在安装了 Facebook 应用程序的设备上运行您的应用程序,您将不会看到此错误。

Error 308occures 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:]).

错误 308发生的原因是,当存储在钥匙串中的值不等于存储在 Facebook 完成参数中的值时(有关更多信息,您可以查看-[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

发生这种情况是因为 Apple 在 iOS 10 中更改了使用钥匙串的方式。要解决此问题,您只需转到 Targets->Capabilities 并启用钥匙串共享(它允许访问您的应用程序的钥匙串): 图片

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

如果您使用的是Xamarin(阅读此链接了解更多信息,感谢 @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.

只需确保在权利中启用钥匙串访问,并选择模拟器(调试)构建的权利。默认情况下未设置。

回答by ZAFAR007

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 LinkSelect Your App and configure your info.plist

转到此链接选择您的应用程序并配置您的info.plist

importand add this code in your AppDelegate

import并将此代码添加到您的 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)
}

回答by umarqattan

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!

是您的 iOS 模拟器没有安装 Facebook 应用程序。在您在 iOS 模拟器上安装应用程序之前,您将继续收到错误消息。尝试在安装了 Facebook 的预配 iOS 设备上运行您的 iOS 应用程序,您将不会再次看到错误消息。希望这可以帮助!

回答by Ruben Marin

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

*由@MoridinBG 在Facebook SDK 的 Github 页面推荐

回答by Code Commander

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.

如果您使用 FBSDKCoreKit 或 FBSDKLoginKit 版本 4.39.0 也可能导致此错误。此版本的 SDK 中存在错误。升级到 4.39.1 或更高版本以修复它。详情请看这里

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.

作为旁注,其他用户提到如果您没有在模拟器上安装 Facebook,则会看到此错误。确实如此,但在未安装应用程序时,SDK 应该会自动回退到 Web 登录方法。如果没有发生,则可能是由另一个问题引起的,例如 Info.plist 中的值丢失/错误配置(检查 LSApplicationQueriesSchemes)或 AppDelegate 上的方法丢失。

回答by da1

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.

就我而言,问题出在 Google Analytics(分析)上。默认情况下,它似乎在应用程序的视图控制器之上添加了自己的视图控制器。在 {Your app}-Info.plist 中将“FirebaseAppDelegateProxyEnabled”设置为“NO”解决了这个问题。