【问题标题】:How to fix loadPersistentStores from crashing on load如何修复 loadPersistentStores 在加载时崩溃
【发布时间】:2019-04-01 15:05:11
【问题描述】:

我正在尝试在 Xcode 上开发一个使用核心数据的应用程序,但是,当我提交该应用程序进行测试审查时,它会在他们的模拟器上崩溃,但不是我的。这是怎么回事?

对于初学者,我最近完成了一个需要一段时间开发的应用程序,然后将其提交到 iTunes Connect。我的应用程序被拒绝,因为“我们无法审查您的应用程序,因为它在启动时崩溃了”。我收到并标出了崩溃发生的路线。

https://imgur.com/a/3iX6pqc

崩溃发生在我的 App Delegate 的第 81 行,正是我去哪里获取持久性容器并加载它。

https://imgur.com/EzQvnSQ

    lazy var persistentContainer: NSPersistentContainer = {
        /*
         The persistent container for the application. This implementation
         creates and returns a container, having loaded the store for the
         application to it. This property is optional since there are legitimate
         error conditions that could cause the creation of the store to fail.
         */
        let container = NSPersistentContainer(name: "AlarmSavedData")
        container.loadPersistentStores(completionHandler: { (storeDescription, error) in

            if let error = error as NSError? {
                print("Here!")
                // Replace this implementation with code to handle the error appropriately.
                // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.



                /*
                 Typical reasons for an error here include:
                 * The parent directory does not exist, cannot be created, or disallows writing.
                 * The persistent store is not accessible, due to permissions or data protection when the device is locked.
                 * The device is out of space.
                 * The store could not be migrated to the current model version.
                 Check the error message to determine what the actual problem was.
                 */
                fatalError("Unresolved error \(error), \(error.userInfo)")

            }
        })
        return container
    }()

我希望本地数据库能够很好地为他们加载,但由于某种原因,我是唯一加载数据库的人。我可以使用它,但是当 Apple Review 团队尝试运行它时,它崩溃了。关于正在发生的事情以及如何解决它的任何想法?目标是让每个用户都拥有自己的本地数据库,使用核心数据来存储他们创建的数据。

崩溃日志:https://imgur.com/a/rx9doSR

【问题讨论】:

  • 您发布的两个 imgur 链接都是您发布的相同代码的屏幕截图。我认为这是一个错误——你想发布部分崩溃报告,这会很有帮助。
  • 您应该查看从 App Review 收到的崩溃报告中的硬件型号和 iOS 版本,并测试您的应用模拟两者。
  • 我在底部添加了崩溃日志。 iOS版本是12.1.4,但我不知道硬件版本在哪里。我只复制了崩溃日志的上半部分和它崩溃的线程。如果您需要更多崩溃报告,请告诉我。

标签: swift core-data app-store-connect


【解决方案1】:

尝试重置模拟器。这为我解决了问题:

【讨论】:

    【解决方案2】:

    首先,请确保您使用 iOS 12.1.4 模拟器测试您的应用,如崩溃报告中所示。崩溃报告表明 Hardware1xxx 这显然是某种占位符,没有帮助。

    我还不能解释崩溃的原因,但这里有一些线索可能会帮助您找到它。

    Apple's TN2151 中,关于您所拥有的 EXC_BREAKPOINT 类型的崩溃,声明如下:

    如果在运行时遇到意外情况,Swift 代码将终止此异常类型,例如:

    • 具有 nil 值的非可选类型

    • 强制类型转换失败

    将此与崩溃发生在loadPersistentStores() 中的事实相结合,这意味着它可能不会为您崩溃,因为您已经在模拟器的模拟磁盘上拥有一个持久存储 - 也就是说,您不是第一次使用.当然,App Review 是第一次使用的用户。因此,您应该从模拟器中删除应用程序的数据,特别是持久存储文件并再次测试。现在您的测试将更像 App Review 的测试。

    你也应该read this answer讨论类似的情况。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-07
      • 2018-01-18
      • 1970-01-01
      • 2021-12-10
      • 1970-01-01
      • 1970-01-01
      • 2019-07-07
      相关资源
      最近更新 更多