The migrateStoreFromURL method gives an error

I am trying to do a db migration as follows:

    NSError                         *error = nil;
    NSMappingModel                  *mapping = [NSMappingModel inferredMappingModelForSourceModel: oldModel destinationModel: self error: &error];

    NSString                        *newContextPath = [contextPath stringByAppendingPathExtension: @"tmp"];
    NSValue                         *classValue = [[NSPersistentStoreCoordinator registeredStoreTypes] objectForKey: NSSQLiteStoreType];
    Class                           sqliteStoreClass = (Class)[classValue pointerValue];
    Class                           sqliteStoreMigrationManagerClass = [sqliteStoreClass migrationManagerClass];
    NSMigrationManager              *manager = [[sqliteStoreMigrationManagerClass alloc] initWithSourceModel: oldModel destinationModel: self];
    @try {
        if (![manager migrateStoreFromURL: srcURL type:NSSQLiteStoreType options:nil withMappingModel:mapping toDestinationURL: dstURL destinationType:NSSQLiteStoreType destinationOptions:nil error:&error]) {
            LOG(@"Migration failed %@", error);
            return NO;
        }
    } @catch (NSException *exception) {
        LOG(@"Exception: %@", exception);
        return NO;
    }

    if (![[NSFileManager defaultManager] removeItemAtPath: contextPath error: &error]) {
        return NO;
    }
    if (![[NSFileManager defaultManager] moveItemAtPath: newContextPath toPath: contextPath error: &error]) {
        return NO;
    }

I get this error when I try to write the current model in db ERROR IN CLIENT libsqlite3.dylib: database integrity is compromised by API violation: vnode disconnected during use: although it was successfully ported. When I try to access the redirected db, it says that it is damaged or garbled and crashing. Not sure what I'm doing wrong. Everything worked fine and still works fine in iOS 10. It only happens in iOS11.

Any help is appreciated. Thanks!

+6
source share

All Articles