Hi, I wanted to know what level of NSFileProtection is provided by default in iOS in the user's documents directory of application container. Basically, if I am creating a file in this location -
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
What level of protection among NSFileProtectionType is provided? `
if my app does not have this entitlement, will the default data protection still be present?
Yes. The entitlement overrides the default. The default is… well… the default (-:
how can I explicitly add data protection to my files?
Best practice is to apply data protection to a file as you create it so the answer depends on what API you’re using. For example:
-
If you use the
write(to:options:)
method onData
, theoptions
parameter supports data protection. -
Core Data has an option to set up data protection.
-
If you’re using Darwin-layer APIs, there’s
open_dprotected_np
[1].
If the API you’re using doesn’t have an option for this, you have two choices:
-
Modify the protection after writing the file by setting the URL’s
.fileProtectionKey
. -
Create a temporary directory, set the data protection on that, and then create your file within that directory. Files written to a directory default to that directory’s data protection.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] Annoyingly, this has no man page (r. 93562342).