当应用程序在后台调用 addPersistentStoreWithType 时,我的 sqlite
文件有时不可用,我收到此错误:
[Model createPersistentStoreCoordinatorWithStoreURL:] line 387 $ sqlite encryption state NSFileProtectionCompleteUntilFirstUserAuthentication error : Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)" UserInfo=0x1560e540 {NSUnderlyingException=authorization denied, NSSQLiteErrorDomain=23}
我发现这是因为文件仍然受到保护(默认为 NSFileProtectionCompleteUntilFirstUserAuthentication
,因此在用户重新启动后第一次解锁他的设备后, protected 数据可用)。不过,我觉得这并不正确,因为我有大量的崩溃,而且我无法想象有多少人在野外重启后仍然锁定他们的设备。
因此,我现在添加我的持久存储协调器,并像这样调整配置
NSDictionary *options = @{
NSMigratePersistentStoresAutomaticallyOption : @YES,
NSInferMappingModelAutomaticallyOption : @YES,
NSPersistentStoreFileProtectionKey : NSFileProtectionNone
};
问题:
- 如果设备被锁定,这是否可以确保文件在后台也可用?
- 如果我更改
NSPersistentStoreFileProtectionKey
,这会破坏 sqlite(/中的数据)吗? - 我没有在数据库中存储敏感数据,但是,您在使用
NSFileProtectionNone
时是否看到安全问题?
最佳答案
- 是的,会的。这就是这把 key 的作用。
- 不,不会。我有一个带有默认保护 key 的持久性存储协调器,然后将其添加到 NSFileProtectionComplete,并且数据正常。
- 是的。如果有人可以访问您的 db 文件,他可以轻松读取它。查看这篇文章:https://github.com/project-imas/encrypted-core-data#strings-comparison
关于ios - 为现有 sqlite 上的持久存储管理器更改 NSPersistentStoreFileProtectionKey,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36450555/