繁体   English   中英

如何在iPhone的docs目录中写入xml文件

[英]how to write xml file in docs directory of iPhone

我需要以这种格式将用户名和密码存储到xml文件中

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

我如何编写此文件,以便可以轻松阅读?

根据@Mike的建议,您应该使用钥匙串来存储密码。

至于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); }
        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM