Facebook iOS Swift SDK:没有得到回调

时间:2016-09-26 23:27:55

标签: ios swift xcode facebook facebook-ios-sdk

我使用facebook入门指南创建一个简单的Facebook登录。 (https://developers.facebook.com/docs/swift/login

每当我点击按钮打开facebook登录视图时,让我登录,但之后不会发起回调。视图保持开放和白色。

let loginButton = LoginButton(readPermissions: [ .publicProfile ])
loginButton.center = view.center

view.addSubview(loginButton)

enter image description here

如果有任何帮助,我所有进入控制台的内容如下:

2016-09-27 01:14:41.294 app[48118:6370539] -canOpenURL: failed for URL: "fbauth2:/" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"

2 个答案:

答案 0 :(得分:1)

原来我错过了AppDelegate部分来处理url打开:

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
  return SDKApplicationDelegate.shared.application(application,
                                                   open: url,
                                                   sourceApplication: sourceApplication,
                                                   annotation: annotation)
}

答案 1 :(得分:0)

您必须允许iOS10的密钥链共享:https://stackoverflow.com/a/39568942/3463712

您必须在info.plist文件中添加以下代码

<key>NSAppTransportSecurity</key>
<dict>
  <!--Include to allow all connections (DANGER)-->
  <key>NSAllowsArbitraryLoads</key>
      <true/>
</dict>

enter image description here

以及

<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fbapi</string>
        <string>fb-messenger-api</string>
        <string>fbauth2</string>
        <string>fbshareextension</string>
    </array>
<!--You need only fbauth2, other parameters are reference for more functionality of Facebook-->

enter image description here

这样做,如果您的问题得到解决,请告诉我。感谢。

修改 可能是你的登录按钮有问题。

下面的代码对我来说很好。

let loginbtn = FBSDKLoginButton()
loginbtn.center = view.center
loginbtn.readPermissions = ["public_profile"];
self.view.addSubview(loginbtn)