ios - FBAuth 不工作 Swift

标签 ios swift facebook

我正在尝试通过 Facebook 将身份验证添加到我的应用程序中,在我的 plist 中:

  <key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>fb146156719258538</string>
        </array>
    </dict>
</array>
<key>FacebookAppID</key>
<string>146156719258538</string>
<key>FacebookDisplayName</key>
<string>applicationTest</string>
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fbapi</string>
    <string>fb-messenger-api</string>
    <string>fbauth2</string>
    <string>fbshareextension</string>
</array>

在我的 AppDelegate 中我有一个方法:

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

    print("app id:" + appId!)
    print("url id:" + String(url.scheme!.hasPrefix("fb\(appId)")))
    print("url host:" + String(describing: url.host))

    if url.scheme != nil && url.scheme!.hasPrefix("fb\(appId)") && url.host ==  "authorize" { // facebook
        return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, options: options)
    }
    return false
}

当在我的 ViewController 中单击 FB 登录按钮时,您会期望执行 AppDelegate 方法的 IF 语句中的代码。然而,这返回 false,我已经调试了代码,看起来该行:

url.scheme!.hasPrefix("fb\(appId)")

即使正在打印正确的 appId,也会返回 false。

有谁知道为什么会这样吗?

P.S:打印 url.scheme 给出:

fb146156719258538

最佳答案

您的 Facebook 帐户设置正确吗?

关于ios - FBAuth 不工作 Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44052019/

相关文章:

html - h2 元素全部聚集在 iOS 和 Firefox 上的顶部图像上

ios - 无法从已安装的 Linkedin 应用程序中获取电子邮件和个人资料图片

swift - SpriteKit : Updating several enemies position to follow the player

ios - Swift DateFormatter 可选毫秒数

iphone - iOS 6 Facebook 发布程序以 "remote_app_id does not match stored id"错误结束

iphone - XCode Interface Builder 中的奇怪颜色?

ios - UIActivityViewController 调用然后关闭后如何执行操作

swift - Xcode 显示冲突的约束

android - 无法保存未经身份验证的 ParseUser

java - 使用我的网络应用程序在 Facebook 上分享图像