Crash on Core Data Migration

末鹿安然 提交于 2019-12-04 15:50:54
Marcus S. Zarra

Starting an answer to update while we work through this.

causing app to crash while migrating, is not a memory crash. That is a watch dog crash.

Migrating large Core Data database crash has no crash log but I suspect it is probably a watchdog as well.

Core Data lightweight migration crash is a watchdog crash as well, not a memory crash.

Once we see your crash we can see what is going on.

Update 1

Ok, 0x8badf00d is our watch dog crash. This means your app is taking too long to launch.

How to fix this?

Don't stand up the core data stack in -applicationDidFinishLaunching... is the short answer.

A quick fix is to have the initial view of your app be identical to the launch image (i.e. splash screen). Then when you launch it finishes -applicationDidFinish... quickly (very quickly) and you can take as long as you want to migrate.

My recommendation (since you don't know how long the migration is going to take is to kick off is to:

  1. Check to see if a migration is necessary with -[NSManagedObjectModel isConfiguration: compatibleWithStoreMetadata:]
  2. Update the view display to let the user know that a migration is occurring
  3. Do the migration in a background block (put the -addPersistentStore... in a block and call it on a background queue, it is thread safe although it is best to put locks around it).
  4. Remove the temporary view when the migration is complete
  5. Launch your real UI.

That should be easy enough to change and gets you past the watchdog.

The following new book on Core Data has code and explanation for how to do a background manual migration as described in the previous answer.

http://www.amazon.com/gp/aw/d/0321905768

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!