ios4 – 在iOS模拟器和设备中测试NSFileProtectionComplete

我在coreData应用程序中为我的 – (NSPersistentStoreCoordinator *)persistentStoreCoordinator编写了这段代码.我使用xCode的Master-Detail Application模板来创建应用程序……
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    if (__persistentStoreCoordinator != nil) {
        return __persistentStoreCoordinator;
    }

    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Notes2.sqlite"];

    NSError *error = nil;
    __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {

        NSLog(@"Unresolved error %@,%@",error,[error userInfo]);
        abort();
    }    

    NSString *urlString = [storeURL absoluteString];
    NSDictionary *fileAttributes = [NSDictionary dictionaryWithObject:NSFileProtectionComplete forKey:NSFileProtectionKey];
    if (![[NSFileManager defaultManager] setAttributes:fileAttributes ofItemAtPath:urlString error:&error]) 
    {
        // Handle error
    }


    return __persistentStoreCoordinator;
}

如何测试并知道我的sqlite已打开NSFileProtectionComplete?

我锁定了模拟器,但是当我在Finder中双击文件时,文件仍然可读.

解决方法

iTunes不会从设备复制文件,除非它有您的密码或设备先前已被信任;这就是它如何解密数据.

在Xcode 8及更早版本中,模拟器使用主机文件系统,macOS当前不支持每个文件加密,就像iOS一样,因此在macOS上你无法在模拟器中测试它.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...