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

标签 ios4 encryption 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;
}

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

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

最佳答案

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

在 Xcode 8 及更早版本中,模拟器使用主机文件系统,而 macOS 目前不像 iOS 那样支持按文件加密,因此在 macOS 上,您无法在模拟器中进行测试。

关于ios4 - 在 iOS 模拟器和设备中测试 NSFileProtectionComplete,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10515253/

相关文章:

iphone - 在标签栏 Controller 的 "more" View 中禁用编辑按钮在 iOS4 中不起作用

使用 AES 的 Android Lollipop 解密无法正常工作

iphone - 在设置我的物理 iPod 进行测试后,让 Xcode 在 iPhone 模拟器上构建我的 iPhone 应用程序?

Xcode 9 - 没有 iOS 11 模拟器

ios - XCode iPhone 模拟器看起来不像 iPhone

iphone - 基础 SDK 缺失错误

iphone - 拉伸(stretch) UIImage 同时保留角点

iphone - llvm-gcc-4.2 : error

Kotlin - 如何检查矩阵中是否存在字符?

c# - .NET Compact Framework 中的 RSA RSACryptoServiceProvider 使用来自完整 .NET Framework 的公钥