iOS - 我可以修改 iPhone 中的实时属性列表文件吗?
我有一个属性列表文件,当我构建程序时,该文件会进入捆绑包。现在,我想用我的 Mac 修改它,并在我的程序运行时更新它。我想捆绑文件不是正确的方法,因为在构建后我似乎无法访问捆绑包的内容。
我应该如何接近?至少使用 iPhone 模拟器工作会很不错,但使用设备工作也会非常好。
I have a property list file which gets to the bundle when I build my program. Now, I would like to be to modify it with my Mac and get it updated while my program is running. I guess bundling the file is not the correct approach, as I do not seem to have any access to the contents of the bundle after it has been built.
How should I approach? It would be nice to work at least with the iPhone simulator but it would be veeery nice to work with the device too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的应用程序包已签名,因此在创建/签名后无法对其进行修改。
为了修改 plist,您需要首先将其复制到应用程序的 Documents 目录中。然后您可以修改副本。这是我在我的一个应用程序中使用的一种方法,该方法在应用程序启动期间将名为FavoriteUsers.plist 的文件从捆绑包复制到文档目录。
Your application bundle is signed, so it can not be modified after it is created/signed.
In order to modify the plist, you need to copy it to the Documents directory for your application first. You can then modify the copy. Here is a method that I have in one of my apps that copies a file called FavoriteUsers.plist from the bundle to the documents directory during app start up.
有点像。您对该捆绑包具有只读访问权限,因此您需要做的是将捆绑包中的 plist 复制到应用程序的文档文件夹中。
文档文件夹是应用程序沙箱的一个区域,您可以在其中读取和写入文件。因此,如果您在第一次启动应用程序时复制该 plist,您将能够根据自己的喜好对其进行编辑和修改。
有人在网上写了一篇教程,基本上回答了您的确切问题,所以与其尝试做我自己的解释,这里有一个更好的教程!
http://iphonebyradix.blogspot.com /2011/03/read-and-write-data-from-plist-file.html
Sort of. You have read-only access to the bundle, so what you need to do is copy over the plist from your bundle into your app's documents folder.
The documents folder is an area of your application's sandbox where you can read and write to files. So if you copy the plist there upon the very first launch of your app, you'll be able to edit and modify it to your heart's content.
There's a tutorial somebody wrote online that basically answers your exact question, so rather than try to do my own explanation here's a much better one!
http://iphonebyradix.blogspot.com/2011/03/read-and-write-data-from-plist-file.html