Core data 数据分开存储 并简单加密

来源:互联网 发布:华为t8300数据恢复 编辑:程序博客网 时间:2024/05/10 05:17
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (persistentStoreCoordinator_ != nil) {
return persistentStoreCoordinator_;
}
persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc]➥

initWithManagedObjectModel:[self managedObjectModel]];

{
NSURL *passwordStoreURL = [NSURL fileURLWithPath: [[self➥
applicationDocumentsDirectory] stringByAppendingPathComponent: @"Passwords.sqlite"]];
NSError *error = nil;
if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType➥
configuration:@"Passwords" URL:passwordStoreURL options:nil error:&error]) {
NSLog(@"Unresolved error with password store %@, %@", error, [error userInfo]);
abort();
}


//加密
NSDictionary *fileAttributes = [NSDictionary➥
dictionaryWithObject:NSFileProtectionComplete forKey:NSFileProtectionKey];
if(![[NSFileManager defaultManager] setAttributes:fileAttributes➥
ofItemAtPath:[passwordStoreURL path] error: &error]) {
NSLog(@"Unresolved error with password store encryption %@, %@", error, [error➥
userInfo]);
abort();
}

}


{
NSURL *notesStoreURL = [NSURL fileURLWithPath: [[self ➥
applicationDocumentsDirectory] stringByAppendingPathComponent: @"Notes.sqlite"]];
NSError *error = nil;
if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType➥
configuration:@"Notes" URL:notesStoreURL options:nil error:&error]) {
NSLog(@"Unresolved error with notes store %@, %@", error, [error userInfo]);
abort();
}
}
return persistentStoreCoordinator_;
}

0 0