我想加密用户手机上保存的所有数据,除非通知需要这些数据。在查看苹果的文档后,NSFileProtectionCompleteUnlessOpen
看起来是我需要的通知中使用的数据,NSFileProtectionComplete
应该为通知不需要的数据做。
我知道这些是 NSFileManager
中的属性,但我不熟悉此类,不想弄错。我已经搜索了 createDirectory 函数调用,它允许我在创建新文件时更改 fileProtectionAttributes,但看起来我们的文件来自不同的来源,所以我需要一种从现有目录设置 fileProtection 属性的方法。
我正在使用 swift 2 和 iOS 8
let files = NSFileManager.defaultManager().enumeratorAtURL(CallIn.DocumentDirectoryURL, includingPropertiesForKeys: nil, options: NSDirectoryEnumerationOptions(), errorHandler: nil)
最佳答案
启用数据保护
使用您选择的加密类型创建权利 plist。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DataProtectionClass</key>
<string>NSFileProtectionComplete</string>
</dict>
</plist>
关于ios - 如何使用 Apple 的数据保护 API 加密我的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36548482/