2010-07-10 4 views
5

J'ai vu une vidéo WWDC 2010 sur NSFileProtectionComplete et la protection des données de l'application.NSFileProtectionComplete pour les applications iOS 4.0

Existe-t-il des exemples? Quelqu'un a-t-il un exemple de code à partager?

+0

Vous devez faire attention. C'est un bon moyen de se tirer une balle dans le pied car le système peut rendre les fichiers illisibles au moment de son choix. – TechZen

+0

Documentation à ce sujet, TechZen? – memmons

Répondre

10

Voir 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.

C'est essentiellement fichier voûte pour les fichiers individuels. Vous passez simplement la constante lorsque vous définissez les attributs de fichier.

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 je suis pressé, alors pouvez-vous m'expliquer ce que fait NSFileProtetionKey au fichier? – satheeshwaran

+0

Si je règle ce comportement sur le fichier de répertoire Documents. Est-il possible d'accéder au fichier sur iDevice Locked State? @TechZen – iTag

Questions connexes