Skip to main content

Fixed : App crash on update with core data changes

Why migration required ?

When the model does not match the store, a migration is required. In order to perform a migration, Core Data (technically, an instance of NSMigrationManager) requires these things:
  • The destination managed object model (the one with the changes)
  • A managed object model that can open the existing store
  • The ability to infer mapping between the two models (for a lightweight migration), or a manual mapping model
  • Permission to attempt to perform an automatic migration (for a lightweight migration)
It is therefore absolutely essential that you never make changes to the managed object model for a released version of an app. That is, if your app is already in the App Store, don’t change a single thing in that version of the managed object model.

Solution for the Crash while update an application from the app store:

Create a new version of the managed object model! This reminds me to mention some other best practices to adopt when working with Core Data:
  • Create a new model version for every release version of an app
  • Keep a copy of every release version of an app (you’re already doing this, right?)
  • Keep a copy of every release version backing SQLite store containing suitable test data

Lightweight Migrations Can Do For You

Remember, you want to use lightweight migrations whenever possible because they are the simplest (and least error prone) option.
Lightweight migrations can handle the following changes:
  • Adding or removing an entity, attribute, or relationship
  • Making an attribute non-optional with a default value
  • Making a non-optional attribute optional
  • Renaming an entity or attribute using a renaming identifier

Steps1:

Replace the function from AppDelegate Class :

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
    
    if (_persistentStoreCoordinator != nil) {
        return _persistentStoreCoordinator;
    }
    
    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"CoreDataDemo.sqlite"];
    
    // handle db upgrade
    NSDictionary *options = @{
                              NSMigratePersistentStoresAutomaticallyOption : @YES,
                              NSInferMappingModelAutomaticallyOption : @YES
                              };
    
    NSError *error = nil;
    _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];
    if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
        // Handle error
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }
    
    return _persistentStoreCoordinator;
}

Step2:

a) Select the model file.
b) Select Editor >> Add Model Version...
c) Leave the version name as 2 and click Finish.
d) Select .xcdatamodeld again (not PassingThoughts.xcdatamodel, that’s the old version) and this time in the File inspector (View\Utilities\Show File Inspector), in the "Model Version" section, select 2 for Current.
e) You should now see a little green circle with white checkmark badge on 2.xcdatamodel in the Project Navigator

Be sure to perform the steps

Detail tutorial from the below link :

Comments

Post a Comment

Popular posts from this blog

iOS9 iTune Upload Error : Invalid Bundle. iPad Multitasking support requires launch story board in bundle

1. Add the UIRequiresFullScreen key to your Xcode project’s Info.plist file and apply the Boolean value YES 2. This will fix one more issue that is coming at the time of iTune upload Invalid Bundle. iPad Multitasking support requires these orientations: 'UIInterfaceOrientationPortrait,UIInterfaceOrientationPortraitUpsideDown,UIInterfaceOrientationLandscapeLeft,UIInterfaceOrientationLandscapeRight'. If your application only using single orientation then use the above keyword in info.plist

iOS Beta Builder

Download iOS Beta Builder 1.0 While I’ve been working on iOS for awhile, I don’t have a ton of experience with Cocoa proper – I’m sure there are probably some issues that slipped through the testing process. Screenshots:   How Does It Work? 1. Build your .ipa file using Xcode’s ‘Build and Archive’ option. Choose ‘Save to Disk’. 2. Launch BetaBuilder (or drag and drop the .ipa on to it). If you need to, select your .ipa file. The app should pre-fill the other details. 3. Enter your intended deployment URL. This is the URL on the Web where your beta will be posted / viewed in a browser. This info gets baked into the deployment file. 4. Hit ‘Generate Deployment Files’ and pick a location to output the files. That’s it – just upload the generated files to your Web server and then hit the URL in the device’s browser. BetaBuilder simply generates the HTML and manifest files needed to make wireless distribution work. As a convenience, it also bundles an iTunes installable

AppCenter SDK integration error while running on device

While running the application on device and added AppCenter SDK. Analytics call showing below error. "An SSL error has occurred and a secure connection to the server cannot be made." Solution:  Add the below code in the info.plist file:      <key> NSAppTransportSecurity </key> <dict> <key> NSExceptionDomains </key> <dict> <key> *.appcenter.com </key> <dict> <key> NSExceptionMinimumTLSVersion </key> <string> TLSv1.2 </string> </dict> </dict> </dict> Your Plist file looks this after adding the above code: <?xml version= "1.0" encoding= "UTF-8" ?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" " http://www.apple.com/DTDs/PropertyList-1.0.dtd " > <plist version = "1.0" > <dict> <key> NSAppTransportSecurity </key> <dict> <key> NSExceptionDom