简体   繁体   English

如何将核心数据文件存储在“专用”文件夹中

[英]How to store the core data files in the Private folder

I have released the iOS app to the user through Adhoc distribution. 我已经通过Adhoc发行版向用户发布了iOS应用。 The user has installed the app and they are able to view the files such as sqlite files, images stored in the documents directory. 用户已经安装了该应用程序,他们能够查看文件,例如sqlite文件,文档目录中存储的图像。 This can be accessed through third party applications such as iExplorer, iMazing. 可以通过第三方应用程序(例如iExplorer,iMazing)进行访问。

Questions: 问题:

1.Is it possible to store the data in private directory and that can't be accessed by other sources or software. 1.是否可以将数据存储在私有目录中,并且其他来源或软件无法访问。

2.Is there any library to encrypt the core data and that shouldn't be read by other applications? 2.是否有用于加密核心数据的库,其他应用程序不应读取?

I have tried with following solutions but that doesn't help the way. 我已经尝试了以下解决方案,但这无济于事。

1.I have used the Data Protection attributes - NSFileProtectionComplete and NSFileProtectionCompleteUnlessOpen. 1.我使用了数据保护属性-NSFileProtectionComplete和NSFileProtectionCompleteUnlessOpen。 But still the data is readable even the device is locked. 但是即使设备被锁定,数据仍然可读。

2.I have tried the SQLCipher library to encrypt the data but it doesn't support for core data framework. 2.我已经尝试使用SQLCipher库对数据进行加密,但是它不支持核心数据框架。

Please advice and thanks. 请指教和谢谢。

You should use the Application Support directory to store your DB files securely. 您应该使用应用程序支持目录安全地存储数据库文件。 You can get the path for that folder like this: 您可以这样获取该文件夹的路径:

let appSupportDirURL = FileManager.default.urls(for:.applicationSupportDirectory, in:.userDomainMask).last

You need to create that directory in a do/catch the first time you use it though: 不过,您需要在第一次使用do / catch时创建该目录:

try FileManager.default.createDirectory(at: appSupportDirURL, withIntermediateDirectories: true, attributes: nil)

Now add your DB file name to that path: 现在,将您的数据库文件名添加到该路径:

let storeURL = appSupportDirURL.appendingPathComponent("MyDatabaseName")

And finally use that url when you call addPersistentStore(ofType:configurationName:at:options:) on your NSPersistentStoreCoordinator to create the DB on disk. 而当你终于打电话使用URL addPersistentStore(ofType:configurationName:at:options:)NSPersistentStoreCoordinator在磁盘上创建数据库。

I don't know of any libraries that help you encrypt the entire Core Data DB, but I actually don't think you need to do that once your DB file is not accessible anymore - at least not for apps with regular security requirements. 我不知道有任何可帮助您加密整个Core Data DB的库,但实际上我认为一旦数据库文件不再可访问,您就不需要这样做-至少对于具有常规安全要求的应用程序而言,这不是必需的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM