Our team has recently added support to our app for Live Activities where the source of the data is driven from the app itself (not push notifications).
We've noticed a crash happening in our core data code caused by the following error thrown by the addPersistentStore
function where it would attempt to recover and eventually crash. Here's an error we created to help us debug that contains the error details:
Domain: CoreData Code: 1 NSLocalizedDescription: Error performing migration for databaseName=mydb.sqlite. Error details=The file couldn’t be saved because you don’t have permission. - userinfo: ["reason": No permissions to create file; code = 1]
After some trouble shooting, we managed to reproduce the issue by doing a hard reboot while we're running a live activity. It appears that when the device starts back up, the Live Activity starts which triggers the app to hit didFinishLaunchingWithOptions
which is where we get our Core Data store initialized.
The problem is that our app uses Data Protection using NSFileProtectionCompleteUntilFirstUserAuthentication
and we'd prefer to keep it that way.
The Core Data db is present in the app sandbox and we're also seeing logs to suggest a failure trying to access NSUserDefaults as well.
Is there an accepted solution for this? Is it expected that a Live Activity would cause an application to launch prior to the device being unlocked for the first time? Is there a way to change that?