Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSFileProtectionComplete for iOS 4.0 apps

I saw a WWDC 2010 video about NSFileProtectionComplete and protecting app's data.

Are there any examples out there? Does any one have sample code to share?

like image 378
OscarTheGrouch Avatar asked Jul 10 '10 03:07

OscarTheGrouch


1 Answers

See the NSFileManager class doc:

The file is stored in an encrypted format on disk and cannot be read from or written to while the device is locked or booting.

It's basically file vault for individual files. You just pass the constant when you set the file attributes.

To mark a file as protected, you must add an extended attribute to it. The Foundation framework includes two ways to add this attribute:

When writing the contents of an NSData object to disk using the writeToFile:options:error: method, include the NSDataWritingFileProtectionComplete option.

Use the setAttributes:ofItemAtPath:error: method of NSFileManager to add the NSFileProtectionKey attribute (with the NSFileProtectionComplete value) to an existing file

.

http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/StandardBehaviors/StandardBehaviors.html

like image 179
TechZen Avatar answered Sep 22 '22 20:09

TechZen