I'm trying to develop an app on Xcode that uses core data, however, when I submit the app for test review it crashes on their simulators, but not mine. What's going on here?
For starters, I've recently finished making an app that took a while to develop and went to submit it to iTunes connect. My App was rejected because "we were unable to review your app as it has crashed on launch". I received and symbolicated the line where the crash happens.
https://i.sstatic.net/SY1Cg.jpg
The crash happens on line 81 in my App Delegate exactly where I go to get my persistent container and load it in.
https://i.sstatic.net/832cz.jpg
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
}()
I expected that the local database would load in just fine for them, but for some reason, I'm the only one that the database loads in for. I'm able to use it but when the Apple Review team tries to run it, it crashes. Any ideas on what's happening and to do to fix it? The goal is for every user to have their own local database using core data to store their created data.
Crash Log : https://i.sstatic.net/WaW8Q.jpg
Try resetting the simulator. That fixed it for me:

First of all, ensure that you are testing your app with a simulator of iOS 12.1.4 as indicated in the crash report. The crash report indicates the Hardware to be 1xxx which is apparently some kind of placeholder, not helpful.
I can't explain the crash yet, but here are some clues that might help you find it.
In Apple's TN2151, regarding the EXC_BREAKPOINT type of crash which is what you have, it is stated:
Swift code will terminate with this exception type if an unexpected condition is encountered at runtime such as:
a non-optional type with a nil value
a failed forced type conversion
Putting this together with the fact that the crash occurs in loadPersistentStores() implies that maybe it is not crashing for you because you already have a persistent store on the simulator's simulated disk – that is, you are not a first-time user. App Review is, of course, a first-time user. So you should remove your app's data, in particular the persistent store file(s), from the simulator and test again. Now your test will be more like App Review's.
You should also probably read this answer which discusses a somewhat similar situation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With