ios SqlCipheer从coredata级联删除崩溃,抛出';n内部一致性异常';删除对象并保存后
我有一个现有的coredata ios 7项目。我想加密我的sqlLite文件。在通过EncryptedStore实现sqlchipher的过程中,当我想要删除一个实体(如E1)时,我面临崩溃,该实体具有一对多的关系,并且与其他实体(如E2)具有删除规则级联 获取日志ios SqlCipheer从coredata级联删除崩溃,抛出';n内部一致性异常';删除对象并保存后,ios,objective-c,core-data,cascading-deletes,sqlcipher,Ios,Objective C,Core Data,Cascading Deletes,Sqlcipher,我有一个现有的coredata ios 7项目。我想加密我的sqlLite文件。在通过EncryptedStore实现sqlchipher的过程中,当我想要删除一个实体(如E1)时,我面临崩溃,该实体具有一对多的关系,并且与其他实体(如E2)具有删除规则级联 获取日志 'NSInternalInconsistencyException', reason: '(null)' 如果我单独删除E2,那么它不会在保存上下文时崩溃 没有sqlcipher,它工作正常 实体删除规则 持久性存储和管理
'NSInternalInconsistencyException', reason: '(null)'
如果我单独删除E2,那么它不会在保存上下文时崩溃
没有sqlcipher,它工作正常
实体删除规则
持久性存储和管理对象上下文的代码
+ (NSPersistentStoreCoordinator *)persistentStoreCoordinatorWithSqliteName: (NSString*)userFolderName fromSqliteFileName:(NSString*) fromSqliteFileNameWithOutExtension shouldCopySQLiteFromBundle:(BOOL)shouldCopyFromBundle withDataModelName:(NSString*)dataModelName
{
static NSPersistentStoreCoordinator *coordinator = nil;
static dispatch_once_t tokenGRC;
dispatch_once(&tokenGRC, ^{
// get the model
NSManagedObjectModel *model = [self managedObjectModelWithName:dataModelName];
// get the coordinator
coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
NSString *sqliteExtension = @"sqlite";
NSString *sqliteFileWithExtension = [[NSString alloc]initWithFormat:@"%@.%@",fromSqliteFileNameWithOutExtension,sqliteExtension];
if (shouldCopyFromBundle == YES) {
NSError *error = nil;
[self copySqliteFromFileName:fromSqliteFileNameWithOutExtension toUserFolder:userFolderName withError:&error];
}
else
{
NSFileManager *defaultManager = [NSFileManager defaultManager];
NSArray* appDocumentDirList= [defaultManager URLsForDirectory:NSDocumentDirectory
inDomains:NSUserDomainMask];
// Append the bundle ID to the URL for the
// Application Support directory
NSURL *dirPath = [[appDocumentDirList objectAtIndex:0] URLByAppendingPathComponent:userFolderName];
NSError *error = nil;
// If the directory does not exist, this method creates it.
// This method is only available in OS X v10.7 and iOS 5.0 or later.
if (![defaultManager createDirectoryAtURL:dirPath withIntermediateDirectories:YES
attributes:nil error:&error])
{
NSAssert2(NO, @"%s Directory could not be created %@",__func__,[error userInfo]);
// Handle the error.
}
}
NSString *customUserDirectory = [[NSString alloc]initWithFormat:@"%@/%@",userFolderName,sqliteFileWithExtension];
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:customUserDirectory];
NSError *error = nil;
// [[NSFileManager defaultManager] removeItemAtURL:databaseURL error:&error];
NSDictionary *options = @{
EncryptedStorePassphraseKey : SampleValue,
// EncryptedStoreDatabaseLocation : databaseURL,
NSMigratePersistentStoresAutomaticallyOption : @YES,
NSInferMappingModelAutomaticallyOption : @YES
};
NSPersistentStore *store = [coordinator
addPersistentStoreWithType:EncryptedStoreType
configuration:nil
URL:storeURL
options:options
error:&error];
// coordinator = [EncryptedStore makeStoreWithOptions:options managedObjectModel:model];
NSAssert(store, @"Unable to add persistent store!\n%@", error);
});
return coordinator;
}
+(A3ManagedObjectContext*)managedObjectContextFromCurrentUser:(NSString*)userName withConcurrencyType:(NSManagedObjectContextConcurrencyType)concurrencyType shouldCopySQLiteFromBundle:(BOOL)shouldCopyFromBundle withSqliteMode:(A3SqliteMode)sqliteMode
{
A3DataFetchMode dataFetchMode = [A3WebUtility currentDataFetchMode];
NSString *fromSqliteName = nil;
NSString *toFolderName = nil;
if (dataFetchMode == A3DataFetchModeOnline) {
fromSqliteName = @"DataBase";
toFolderName = userName;
}
else
{
fromSqliteName = @"DataBase-Demo";
toFolderName = @"DemoUser";
}
NSString *dataModelName = [self dataModelNameForSqliteMode:sqliteMode];
NSPersistentStoreCoordinator *coordinator = [A3ManagedObjectContext persistentStoreCoordinatorWithSqliteName:toFolderName fromSqliteFileName:fromSqliteName shouldCopySQLiteFromBundle:shouldCopyFromBundle withDataModelName:dataModelName];
if (coordinator != nil) {
A3ManagedObjectContext *tempManagedContext = [[A3ManagedObjectContext alloc]initWithConcurrencyType:concurrencyType];
[tempManagedContext setPersistentStoreCoordinator:coordinator];
tempManagedContext.sqliteMode = sqliteMode;
return tempManagedContext;
}
else
{
return nil;
}
}