【问题标题】:Testing NSFileProtectionComplete in iOS simulator and device在 iOS 模拟器和设备中测试 NSFileProtectionComplete
【发布时间】:2012-05-17 22:03:18
【问题描述】:

我在 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 和 iTunes 文件共享将文件从设备复制到我的桌面……但文件仍然可读。
  • 你能测试一下吗?

标签: ios4 encryption ios-simulator ios5


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-24
    • 1970-01-01
    • 2018-05-21
    • 1970-01-01
    • 2012-12-31
    • 2012-02-19
    • 1970-01-01
    • 2015-07-27
    相关资源
    最近更新 更多