Sto cercando di trovare informazioni sulla gestione degli errori durante la creazione di un coordinatore di negozio persistente su iPhone. Ho implementato la migrazione leggeraGestione degli errori in addPersistentStoreWithType
NSError *error = nil;
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
/*
Replace this implementation with code to handle the error appropriately.
abort() 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 persistent store is not accessible;
* The schema for the persistent store is incompatible with current managed object model.
Check the error message to determine what the actual problem was.
If the persistent store is not accessible, there is typically something wrong with the file path. Often, a file URL is pointing into the application's resources directory instead of a writeable directory.
If you encounter schema incompatibility errors during development, you can reduce their frequency by:
* Simply deleting the existing store:
[[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil]
* Performing automatic lightweight migration by passing the following dictionary as the options parameter:
@{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES}
Lightweight migration will only work for a limited set of schema changes; consult "Core Data Model Versioning and Data Migration Programming Guide" for details.
*/
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return _persistentStoreCoordinator;
Questo è basato sul codice di Apple con il supporto aggiunto per la migrazione leggera.
Non riesco a trovare alcuna informazione sulla gestione degli errori se l'applicazione riscontrasse ancora un errore qui. Mi sembra che se non è possibile creare il database, l'applicazione non può essere utilizzata affatto.
- Devo solo chiedere all'utente di provare a reinstallare l'applicazione e visualizzare le informazioni rilevanti?
- È possibile mantenere l'istruzione abort() durante l'aggiunta di un prompt sull'errore o ciò causerà il rifiuto dell'applicazione da parte di Apple?
Grazie per il vostro aiuto Ho aggiunto il tentativo di eliminare il database e quindi di crearlo nuovamente poiché il database non può essere caricato da un server. Se ancora non riesce, a questo punto cosa posso fare? –
Questo sarebbe un errore fatale che non dovrebbe verificarsi normalmente, quindi * penso * sarebbe opportuno interrompere() in tal caso, in modo da ottenere i registri degli arresti anomali che informano sul problema. –