更新文件共享文件夹中的 plist 文件 - 我真的需要建议

发布于 2024-09-24 16:58:41 字数 192 浏览 4 评论 0原文

我需要打开位于文件共享文件夹中的 plist 文件,以便在每次启动应用程序时添加两条用户信息;如用户的新名称和电子邮件(两者都是 NSString 类型,plist 文件是 Dictionary)。

然后需要再次将文件保存回文件共享文件夹,以便稍后可以通过 iTunes 删除新更新的 plist 文件。

如果有人可以提供帮助,将不胜感激

I need to open a plist file located in the File Sharing folder, to add two pieces of user info to each time the app is launched; as in a new Name and Email of the user (both are of type NSString and the plist file is Dictionary).

It then needs to save the file back to the File Sharing folder again, so that the new updated plist file can be removed at a later time via iTunes.

If anyone could help it would be greatly appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

平安喜乐 2024-10-01 16:58:41

可以将 plist 存储在 Documents 目录中。您将能够将 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。

Storing a plist in the Documents directory is possible. You will be able to load the plist into an NSMutableDictionary, modify the dictionary and write it back out to the Documents directory.

// 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];

I don't know that you will be able to remove the plist via iTunes.

坏尐絯 2024-10-01 16:58:41

我发现的另一个很棒的资源是“Humble Coder”博客的一篇文章,位于以下位置。很好的建议,示例代码非常适合我保存、检索和更新 plist 文件的需要。再次感谢那些提供帮助的人。

http://humblecoder.blogspot.com/2010/03/重新访问-存储和检索.html

Another great resource that I found was an article by the "Humble Coder's" blog at the following location. Great advice and the example code was spot on for my need to save retrieve and update my plist files. Thank you again to those that helped.

http://humblecoder.blogspot.com/2010/03/revisited-storing-and-retrieving.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文