J'ai un problème avec mon application, CoreData fonctionne comme il devrait dans le simulateur - mais pas sur l'appareil.CoreData "Erreur lors de la validation de l'URL pour le stockage"
Je reçois un
2010-09-30 12:45:07.500 CoreDataTutorial_iOS[130:307] Unresolved error Error Domain=NSCocoaErrorDomain Code=513 "The operation couldn’t be completed. (Cocoa error 513.)" UserInfo=0x1412a0 {NSUnderlyingException=Error validating url for store}, {
NSUnderlyingException = "Error validating url for store";
J'appelle la PersistentStoreCoordinator dans cette fonction (qui jette l'erreur ci-dessus):
-(NSPersistentStoreCoordinator*)persistentStoreCoordinator
{
if(persistentStoreCoordinator_ != nil)
return persistentStoreCoordinator_;
NSURL *aStoreURL = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingFormat:@"corebase.sqlite"]];
NSError *anError = nil;
persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if(![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:aStoreURL options:nil error:&anError])
{
NSLog(@"Unresolved error %@, %@", anError, [anError userInfo]);
abort();
}
return persistentStoreCoordinator;
}
J'installe un point de rupture, sur « objc_exception_throw », pour voir ce que le aStoreURL est, et il est: fichier : //localhost/var/mobile/Applications/BE9A2982-BDC3-405D-A201-FB78E9E0790B/Documentscorebase.sqlite
Je remarque que ce n'est pas en ajoutant lui-même le final "/" après "/ Documents". Lorsque j'ai créé l'URL de cette façon
NSURL *aStoreURL = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingFormat:@"/corebase.sqlite"]];
Il semble avoir travaillé, ou tout au moins cette partie se est passé. Cette fonction ne doit-elle pas être ajoutée à cette partie?
-(NSString*) applicationDocumentsDirectory
{
return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
}
Cela fonctionne très bien dans le simulateur, quelle est la bonne pratique?