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

Osc*_*uch 7 encryption ios4 ios-simulator ios5

我在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;
}
Run Code Online (Sandbox Code Playgroud)

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

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

rus*_*hop 0

iTunes 不会从设备复制文件,除非它有您的密码或该设备之前已被信任;这就是它解密数据的方式。

在 Xcode 8 及更早版本中,模拟器使用主机文件系统,并且 macOS 目前不支持与 iOS 相同的每个文件加密,因此在 macOS 上,您无法在模拟器中对此进行测试。