我需要打开位于文件共享文件夹中的 plist 文件,以在每次启动应用程序时添加两条用户信息;就像在用户的新名称和电子邮件中一样(两者都是 NSString 类型,plist 文件是 Dictionary)。
然后它需要再次将文件保存回文件共享文件夹,以便以后可以通过 iTunes 删除新更新的 plist 文件。
如果有人可以提供帮助,将不胜感激
我需要打开位于文件共享文件夹中的 plist 文件,以在每次启动应用程序时添加两条用户信息;就像在用户的新名称和电子邮件中一样(两者都是 NSString 类型,plist 文件是 Dictionary)。
然后它需要再次将文件保存回文件共享文件夹,以便以后可以通过 iTunes 删除新更新的 plist 文件。
如果有人可以提供帮助,将不胜感激
可以在 Documents 目录中存储 plist。您将能够将 plist 加载到 NSMutableDictionary 中,修改字典并将其写回 Documents 目录。
// get the path to the plist file
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"myfile.plist"];
// read the plist into an NSMutableDictionary
NSMutableDictionary *plistDictionary = [NSMutableDictionary dictionaryWithContentsOfFile:filePath];
// make the additions to the plistDictionary
// write the plist back to the documents directory
[plistDictionary writeToFile:filePath atomically:YES];
我不知道您是否可以通过 iTunes 删除 plist。
我发现的另一个很好的资源是“Humble Coder's”博客的一篇文章,位于以下位置。很好的建议和示例代码,因为我需要保存检索和更新我的 plist 文件。再次感谢那些帮助过的人。
http://humblecoder.blogspot.com/2010/03/revisited-storing-and-retrieving.html