실제로 NSKeyedArchiver archiveRootObject를 호출하고 파일 속성을 NSFileProtectionComplete 또는 NSFileProtectionCompleteUnlessOpen으로 설정하는 데이터 보호 API로 작업 할 수 있습니까?NSKeyedArchiver archiveRootObject 및 NSFileProtectionComplete/NSFileProtectionCompleteUnlessOpen
3
A
답변
6
오브젝트를 특정 위치 (이 경우 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 {
[email protected](%@", error);
}
}
나의 현재 구현은 사용 + (BOOL) archiveRootObject (ID) rootObject TOFILE (있는 NSString *) 경로 하지만 그 NSFileProtectionComplete의 함께 작동 할 수 있는지 어떤 정보를 찾을 수없는 것 – jdrm
내 솔루션이 효과가 있는지 알려 주시기 바랍니다. 나는 나의 대답을 최신의 것으로 바꿨다 – ekims