Why is App crashing when loading a pre populated DB into Core Data upon first open on Older Devices?

前端 未结 1 533
故里飘歌
故里飘歌 2021-01-25 13:56

With my App I have a pre-populated sqlite DB that I created using core data from another app I created so the Data model is the same. I copy it over and everything works great.

1条回答
  •  礼貌的吻别
    2021-01-25 14:24

    You are copying the data on the main thread, which blocks it far too long. It should never ever be blocked for 1 second or longer. Otherwise the iOS watchdog will kill your process.

    The specific crash report shows the app was killed, because it took too long to start up: com.JonPhillips.Upgrade failed to launch in time.

    The copy action is even running from inside applicationDidFinishLaunching. The watchdog timer is even shorter for having this method end! Check the WWDC sessions for exact timing if you are interested in them. I don't recall in which specifically it was mentioned.

    If you require such tasks, move them to a background thread. If this tasks means that the user cannot do anything in the app, show a specific UI telling the user what is going on and giving some indication how long it will take, e.g. a progress bar, and/or some text "Step 1 of 3: Copying data".

    0 讨论(0)
提交回复
热议问题