在应用程序处于后台时调用 addPersistentStoreWithType 时,我的sqlite
文件有时不可用并且我收到此错误:
[Model createPersistentStoreCoordinatorWithStoreURL:] line 387 $ sqlite 加密状态 NSFileProtectionCompleteUntilFirstUserAuthentication 错误:错误域=NSCocoaErrorDomain Code=256“操作无法完成。(Cocoa 错误 256。)”UserInfo=0x1560e540 {NSUnderlyingException=授权被拒绝,NSSQLiteErrorDomain=23}
我发现这是因为该文件仍然受到保护(默认情况下NSFileProtectionCompleteUntilFirstUserAuthentication
,用户在重新启动后第一次解锁他的设备后,受保护的数据可用)。我觉得这行为不正确,因为我有大量的崩溃,我无法想象很多人在野外重启后仍然锁定他们的设备。
因此,我现在正在添加我的持久存储协调器,并像这样调整配置
NSDictionary *options = @{
NSMigratePersistentStoresAutomaticallyOption : @YES,
NSInferMappingModelAutomaticallyOption : @YES,
NSPersistentStoreFileProtectionKey : NSFileProtectionNone
};
问题:
- 如果设备被锁定,这是否可以确保文件在后台也可用?
- 如果我更改,这会破坏 sqlite(/ 内部数据)
NSPersistentStoreFileProtectionKey
吗? - 我没有在数据库中存储敏感数据,但是,您在使用时是否看到安全问题
NSFileProtectionNone
?