2010-07-10 3 views
5

Ho visto un video WWDC 2010 su NSFileProtectionComplete e protegge i dati dell'app.NSFileProtectionComplete per app iOS 4.0

Ci sono degli esempi là fuori? Qualcuno ha un codice di esempio da condividere?

+0

Devi essere attenti a questo. È un buon modo per spararti nel piede perché il sistema può rendere illeggibili i file nel momento in cui sceglie. – TechZen

+0

Documentazione su questo, TechZen? – memmons

risposta

10

vedere la classe NSFileManager 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.

è fondamentalmente vault per i singoli file. È sufficiente passare la costante quando si impostano gli attributi del file.

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

Ehi, sono di fretta, quindi puoi spiegarmi che cosa fa NSFileProtetionKey sul file ?? – satheeshwaran

+0

Se si imposta questo comportamento sul file di directory Documenti. È possibile accedere al file su IDevice Locked State? @TechZen – iTag