开发者

How do I add Data Protection Class Entitlements to my iOS 5 app

I have been all over the web including Apple's dev site but I can't find any instruction on how to s开发者_运维技巧et 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


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>


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜