2010-07-10 6 views
5

Ich habe ein WWDC 2010-Video über NSFileProtectionComplete gesehen und die Daten der App geschützt.NSFileProtectionComplete für iOS 4.0-Apps

Gibt es irgendwelche Beispiele? Hat jemand einen Beispielcode zum Teilen?

+0

Sie müssen vorsichtig damit sein. Es ist eine gute Möglichkeit, sich in den Fuß zu schießen, da das System die Dateien zu einem Zeitpunkt der Wahl unlesbar machen kann. – TechZen

+0

Dokumentation dazu, TechZen? – memmons

Antwort

10

Siehe NSFileManager Klasse 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.

Es ist im Grunde für einzelne Dateien File Vault. Sie übergeben die Konstante nur, wenn Sie die Dateiattribute festlegen.

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

+0

Hey, ich bin in Eile, also kannst du mir bitte erklären, was NSFileProtetionKey eigentlich mit der Datei macht ?? – satheeshwaran

+0

Wenn ich dieses Verhalten auf Documents-Verzeichnis-Datei einstelle.Ist es möglich, auf die Datei auf IDevice Locked State zuzugreifen? @TechZen – iTag