jdr*_*drm 3 nskeyedarchiver ios
实际上是否可以调用NSKeyedArchiver archiveRootObject并使用数据保护API将文件属性设置为NSFileProtectionComplete或NSFileProtectionCompleteUnlessOpen?
首先尝试将对象写入特定位置,在本例中为docFile(这是设置为文档目录).然后将文件属性应用于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);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2336 次 |
| 最近记录: |