Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Loss of Coredata sqlite file with app upgrade

theNigetheNige TewkesburyPosts: 3 Noob
The latest upgrade of one of my apps resulted in the user losing their data! One change I made was to copy the original file (if there) from \Documents\myapp.sqlite to \Documents\Store\myappDB.sqlite. I think this must be part of the problem, and yet I cannot reproduce the problem on my own iPhone. My code is shown below where storeURL points to the new location, and leagacyStoreUrl to the old location.
Can anyone see why this wouldn't work for the users, but works fine on my iPhone?


BOOL stillUsingLegacyStore = YES;
stillUsingLegacyStore = !([fileManager fileExistsAtPath:self storeURL] path);
if ([fileManager fileExistsAtPath:self legacyStoreURL] path && stillUsingLegacyStore==YES)
{
_store = [_coordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:[self legacyStoreURL]
options:options
error:&error];
if (!_store)
{
FLOG(@Error adding OLD persistent store to coordinator %@\n%@",
[error localizedDescription], [error userInfo]);
return;
}

_store = [_coordinator migratePersistentStore:_store
toURL:[self storeURL]
options:options
withType:NSSQLiteStoreType
error:&error];
if (!_store)
{
FLOG(@Error adding OLD persistent store to coordinator %@\n%@",
[error localizedDescription], [error userInfo]);
return;
}
}
else
{
_store = [_coordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:[self storeURL]
options:options
error:&error];
if (!_store)
{
NSLog(@Failed to add store. Error: %@", error);abort();
return;
}
else
{
NSLog(@Successfully added store: %@", _store);
}

}

Replies

  • lightbowlightbow Brooklyn, NYPosts: 1 Noob
    I am also struggling with reports of user data loss. It seems that migratePersistentStore is silently dropping all CoreData many-to-many relationships. I only have one of those in my data model, but it is a very important one! Does anyone know of a better way to properly "Save As..." to a single file?
Sign In or Register to comment.