2012-02-03 3 views
0
내가 쉽게 읽을 수 있도록 나는이 파일을 쓸 수있는 방법이 형식

방법 아이폰

<user>abcde</user> 
    <pass>123355</pass> 

에 XML 파일로 내 사용자 이름과 암호를 저장해야

의 문서 디렉토리에 XML 파일을 작성하는?

+0

비밀번호와 같은 '비밀'을 저장하는 경우 키 체인을 사용해야합니다. –

+0

어떻게 할 수 있습니까? – Ali

답변

0

@Mike가 제안한 바에 따르면 키 체인을 사용하여 암호를 저장해야합니다 .Google은 온라인에서 사용할 수있는 자습서를 제공합니다.

xml 저장에 관해서는. 다음은 코드입니다

 NSData *serializedData; 
     NSString *error; 
     serializedData = [NSPropertyListSerialization dataFromPropertyList:YourArray(You can use dictionaries.strings..and others too) 
     format:NSPropertyListXMLFormat_v1_0 errorDescription:&error]; 
     if (serializedData) { 
     // Serialization was successful, write the data to the file system // Get an array of paths. 

     NSArray *documentDirectoryPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
     NSString *docDir = [NSString stringWithFormat:@”%@/serialized.xml”, 
     [documentDirectoryPath objectAtIndex:0]]; 
     [serializedData writeToFile:docDir atomically:YES]; 
} 
     else { 
     // An error has occurred, log it 
     NSLog(@”Error: %@”,error); } 
     }