Is it actually possible to call NSKeyedArchiver archiveRootObject and work with data protection API setting the file attribute to NSFileProtectionComplete or NSFileProtectionCompleteUnlessOpen ?
Asked
Active
Viewed 2,384 times
3
-
My current implementation uses + (BOOL)archiveRootObject:(id)rootObject toFile:(NSString *)path But I've not being able to find any information to see if that can work in conjunction of NSFileProtectionComplete – jdrm Nov 20 '12 at 17:37
-
please let me know if my solution worked for you. I've updated my answer – brightintro Nov 20 '12 at 21:03
1 Answers
6
First attempt to write the object to the specific location, in this case docFile (this is set to the documents directory). Then apply the file attributes to the docFile.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex: 0];
NSString* docFile = [docDir stringByAppendingPathComponent: @"Somefile.plist"];
NSError* error;
if([NSKeyedArchiver archiveRootObject:tempData toFile:docFile]) {
NSDictionary *fileAttributes = [NSDictionary
dictionaryWithObject:NSFileProtectionComplete
forKey:NSFileProtectionKey];
if([[NSFileManager defaultManager] setAttributes:fileAttributes
ofItemAtPath:docFile error: &error]) {
NSLog(@"Success");
}
else {
NSLog@(%@", error);
}
}

brightintro
- 1,016
- 1
- 11
- 16
-
-
Yeah looks like it works ...it doesn't let me read the file after the device gets locked...thanks! – jdrm Nov 22 '12 at 17:17