我正在尝试在Xcode上开发一个使用核心数据的应用程序,但是,当我提交应用程序进行测试审查时,它会在他们的模拟器上崩溃,但不是我的。这里发生了什么?
对于初学者,我最近完成了一个需要一段时间才能开发的应用程序并将其提交到iTunes连接。我的应用被拒绝是因为“我们无法审核您的应用,因为它已在发布时崩溃”。我接收并象征了崩溃发生的路线。
崩溃发生在我的App Delegate的第81行,正好是我去获取持久容器并加载它的地方。
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团队尝试运行它时,它会崩溃。有关正在发生的事情和要解决的问题的任何想法?目标是让每个用户都拥有自己的本地数据库,使用核心数据来存储他们创建的数据。
首先,确保您使用崩溃报告中指示的iOS 12.1.4模拟器测试您的应用程序。崩溃报告显示硬件为1xxx,这显然是某种占位符,没有帮助。
我还无法解释崩溃,但这里有一些线索可能会帮助你找到它。
在Apple's TN2151中,关于你所拥有的EXC_BREAKPOINT类型的崩溃,它被声明:
如果在运行时遇到意外情况,则Swift代码将以此异常类型终止,例如:
将这一点与loadPersistentStores()
中发生崩溃的事实相结合意味着它可能不会因为你已经在模拟器的模拟磁盘上有持久存储而崩溃 - 也就是说,你不是第一次使用的用户。 App Review当然是首次使用的用户。因此,您应该从模拟器中删除应用程序的数据,特别是持久性存储文件,然后再次进行测试。现在你的测试将更像是App Review。
你也应该read this answer讨论一个类似的情况。