Our app has a bundled SQL database which we copy from the bundle using the default FileManager.
application:didFinishLaunchingWithOptions:
The database has a version number which we store in the NSUserDefaults.
This has worked without any problems until recently when we needed to update the database. We detect the upgrade is required and delete the old .sqlite file from the FileManager and replace with the new bundle value. This was done in the didFinishLaunchingWithOptions prior to the app reading any of the data.
For the majority of our users this approach as worked well but for a minority their database has become corrupted in some way and they get the
NSObjectInaccessibleException CoreData could not fulfill a fault
whenever they try and access the data. People state that this exception typically occurs when you have multiple threads editing the data in the database. However our data is static with no updates or edits. We have a single managedObjectContext and we use a NSFetchedResultsController to show the data in a UITableViewController.
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
The app remains in a corrupted state, even after restarting the device.
Can anyone explain what might be happening and how we change the approach to prevent it from happening or how we might recover once a Fault is detected?
We have tried detecting the Faults using
if ([self.managedObjectContext existingObjectWithID:[theState objectID] error:&error]) {
//display object details
} else {
//need to recover from corrupt data
}
Aucun commentaire:
Enregistrer un commentaire