Reputation: 1286
I forgot to do core data migration
before submitting new version of my app.When having installed Older version and update to new version , upon launch, the app crashes EVERY time.
When deleting new version and reinstalling the app, all works fine. We are talking prod versions on App Store.
Could you please tell me how i can fix this?
Upvotes: 0
Views: 67
Reputation: 583
Your you have to do lightweight migration :-
Make two Version of Datamodel [Safe]
Somthing like this:-
+ (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if ([DBHelper sharedCoreDataInstance].objPersistentStoreCoordinator != nil) {
return [DBHelper sharedCoreDataInstance].objPersistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationLibraryDirectory] URLByAppendingPathComponent:@"yourdb.sqlite"];
NSError *error = nil;
NSDictionary *options = @{
NSMigratePersistentStoresAutomaticallyOption : @YES,
NSInferMappingModelAutomaticallyOption : @YES
};
[DBHelper sharedCoreDataInstance].objPersistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc]
initWithManagedObjectModel:[self managedObjectModel]];
if(![[DBHelper sharedCoreDataInstance].objPersistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:storeURL
options:options
error:&error])
{
//Error for store creation should be handled in here
}
return [DBHelper sharedCoreDataInstance].objPersistentStoreCoordinator;
}
Upvotes: 1
Reputation: 6065
You can submit a version which does the data migration.
If users update from 1.0 -> 1.2 it should work. If users have already updated to 1.1 (did crash), the app could not change the data, so it should be ok if they updated from 1.1 -> 1.2 (But anyway try your self, if I am right)
Worst case: I do not know what kind of data you have in core data, but if it is reconstructable, you can just delete the old data and create a new one.
Upvotes: 1