如何将数据保护类权利添加到我的 iOS 5 应用程序

发布于 2024-11-28 23:38:59 字数 279 浏览 1 评论 0原文

我已经浏览了整个网络,包括苹果的开发网站,但我找不到任何有关如何设置应用程序的 /Documents 目录属性 NSFileProtectionKey = NSFileProtectionComplete 的说明。我已经在应用程序第一次运行时设置了该值,但是有没有办法以其他方式设置它?就像通过一些 X 代码复选框、plist 或其他。

另请注意:存储在数据保护类别为 NSFileProtectionComplete 的目录下的任何文件是否会自动被视为与其目录相同的保护类别?

非常感谢,

菲什

I have been all over the web including Apple's dev site but I can't find any instruction on how to set an app's /Documents directory attribute NSFileProtectionKey = NSFileProtectionComplete. I have set the value upon the first time the app runs but is there a way to set it otherwise? Like through some X-Code check box, plist, or other.

Also on a related note: Are any files stored under a directory with the data protection class of NSFileProtectionComplete automatically treated as the same protection class as its directory?

Thanks a bunch,

Fissh

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

千仐 2024-12-05 23:38:59

要保护应用程序 Documents 目录中的文件,无需任何代码,您必须向应用程序添加 entitlements.plist。

在 entitlements.plist 中,添加“DataProtectionClass”键和“NSFileProtectionComplete”值。只要设备锁定,您的文件就会自动受到保护。

这是一个例子

<?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>

To protect files in your application Documents directory, without any code, you have to add an entitlements.plist to your application.

In your entitlements.plist, add the "DataProtectionClass" key, with the "NSFileProtectionComplete" value. Your files will be automatically protected as long as the device is locked.

Here is an example

<?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>
话少情深 2024-12-05 23:38:59

WWDC 会议 208 对此进行了轻松讨论,我认为您可以使用该密钥创建一个权利文件,并且不需要编写代码。

我还没有这样做,所以我不完全确定它是否有效。

WWDC session 208 breezed over this, I think you create an entitlements file with that key, and you don't need to write code.

I haven't done this yet so I'm not completely sure it works.

澉约 2024-12-05 23:38:59

这是我想出的技巧,直到我弄清楚如何正确设置 /Documents 目录保护。

NSError *error;
NSDictionary *attrs = [self attributesOfItemAtPath:DOCUMENTS_FOLDER error:&error];
if(![[attrs objectForKey:NSFileProtectionKey] isEqual:NSFileProtectionComplete])
{
    attrs = [NSDictionary dictionaryWithObject:NSFileProtectionComplete forKey:NSFileProtectionKey];
    BOOL success = [self setAttributes:attrs ofItemAtPath:DOCUMENTS_FOLDER error:&error];
    if (!success) 
        NSLog(@"Set ~/Documents attr NOT successfull");
}

我只是在加载应用程序时调用上面的代码,以设置文档目录保护(如果尚未设置)。

菲什

This is the hack I came up with until I figure out how to set the /Documents directory protections correctly.

NSError *error;
NSDictionary *attrs = [self attributesOfItemAtPath:DOCUMENTS_FOLDER error:&error];
if(![[attrs objectForKey:NSFileProtectionKey] isEqual:NSFileProtectionComplete])
{
    attrs = [NSDictionary dictionaryWithObject:NSFileProtectionComplete forKey:NSFileProtectionKey];
    BOOL success = [self setAttributes:attrs ofItemAtPath:DOCUMENTS_FOLDER error:&error];
    if (!success) 
        NSLog(@"Set ~/Documents attr NOT successfull");
}

I just call the above code upon loading of the app, to set the documents directory protection if it is not set already.

Fissh

十年不长 2024-12-05 23:38:59

http://devforums.apple.com/message/627887
开发者论坛:Apply DataProtectionClass Entitlement

我找到了此链接,并且此 Entitlements 方法当前不起作用并针对错误问题进行了归档,因此我们必须逐个文件进行操作。

http://devforums.apple.com/message/627887
Developer Forums: Apply DataProtectionClass Entitlement

I found this link, and this Entitlements method currently not working and filed for the bug issue, so we would have to do file by file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文