ios - Facebook 登录使应用程序崩溃

标签 ios swift facebook

我用 SpriteKit 和 Swift 4 开发了一款游戏,其中集成了 Facebook。我的应用程序支持 iOS 9 或更高版本。是的,我知道建议使用驼峰式而不是蛇式。

最近,我的应用程序在 facebook 登录时崩溃,大约 90% 的时间。剩下的 10% 可以按预期工作。谁能指出是什么导致了这个问题以及如何解决它?

podfile中我包含:

 pod 'FacebookCore'
 pod 'FacebookLogin'

在我的 AppDelegate 中我添加了:

import FacebookLogin
import FacebookCore
import FBSDKLoginKit

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

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool
{
    return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: nil)
}

此外,我的 .plist 看起来像这样。

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>fb282293049303792</string>
        </array>
    </dict>
</array>
<key>FacebookAppID</key>
<string>282293049303792</string>
<key>FacebookDisplayName</key>
<string>Squares</string>
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fbapi</string>
    <string>fb-messenger-api</string>
    <string>fbauth2</string>
    <string>fbshareextension</string>
</array>

但是当我运行登录代码时,应用程序因此错误而崩溃。

func facebook_login()
{
    let login_manager = LoginManager()

    login_manager.logIn(readPermissions: [.publicProfile, .email], viewController: self.view?.window?.rootViewController)
    {
        (result) in

        switch result
        {
            case .success(grantedPermissions: _, declinedPermissions: _, token: _):
                self.get_facebook_data()
                break

            case .failed(let err):
                print(err)
                self.show_error(type: "fb_login_failed")
                break

            case .cancelled:
                print("canceled")
                self.show_error(type: "fb_login_cancelled")
                break
        }
    }
}

无论结果成功失败还是取消,它仍然会崩溃AppDelegate

enter image description here

最佳答案

此问题已通过将手机更新到最新的 iOS 12.1.4 得到解决。显然 Facebook 库在之前的 iOS 版本上崩溃了。

关于ios - Facebook 登录使应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54595229/

相关文章:

ios - 如何使用 avfoundation 合并视频剪辑?

快速使用未解析的 FbAppCall

android - 使用默认身份验证在 FB 上发布照片并获取照片已发布的消息的简单技术

uitableview - 如何将自定义图像添加到 uitableview 单元格滑动以删除

javascript - Facebook 登录 Django 和 url 重定向?

ios - 试图快速从 firebase 数据库中获取用户

ios - XCode 在路径中没有有效的编译 Storyboard

ios - 从包含 User 类对象的 NSMutableArray 获取基于属性的唯一对象

ios - 动态单元格高度尺寸不起作用

swift - Swift 中的 kAudioUnitProperty_MatrixLevels