2012-11-20 4 views
3

실제로 NSKeyedArchiver archiveRootObject를 호출하고 파일 속성을 NSFileProtectionComplete 또는 NSFileProtectionCompleteUnlessOpen으로 설정하는 데이터 보호 API로 작업 할 수 있습니까?NSKeyedArchiver archiveRootObject 및 NSFileProtectionComplete/NSFileProtectionCompleteUnlessOpen

+0

나의 현재 구현은 사용 + (BOOL) archiveRootObject (ID) rootObject TOFILE (있는 NSString *) 경로 하지만 그 NSFileProtectionComplete의 함께 작동 할 수 있는지 어떤 정보를 찾을 수없는 것 – jdrm

+0

내 솔루션이 효과가 있는지 알려 주시기 바랍니다. 나는 나의 대답을 최신의 것으로 바꿨다 – ekims

답변

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); 
    } 
} 
+0

나는 길에있다 나는 집에 돌아갈 때 그것을 시험해 볼 것이다. .. 고마워! – jdrm

+0

그래도 작동하는 것처럼 보입니다 ... 장치가 잠긴 후에 파일을 읽지 못하게됩니다 ... 감사합니다! – jdrm