在应用程序中存储 iPhone 应用程序设置
我的 iPhone 应用程序几乎没有用户可能经常更改的设置。我想知道是否有任何建议的方法来处理此类设置(读取和保存它们)。在Apple网站上,我只找到了一个有关将应用程序设置与“设置”应用程序集成的教程(链接),但我不希望用户退出我的应用程序,这样他就可以更改选项。
应用程序本身是否有任何默认机制来处理此类设置,或者我是否必须实现自己的解决方案?
My iPhone app has few settings that users is likely to change quite often. I would like to know if there's any suggested way of handling such settings (reading and saving them). On Apple sites I found only a tutorial about integrating your application settings with Settings app (link) but I don't want a user to exit my app so he could just change the option.
Is there any default mechanism to handle such settings in app itself or do I have to implement a solution of my own?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 iPhone 中存储设置的最佳且最简单的方法是通过 <代码>NSUserDefaults。让您不必处理文件系统或 plist 或任何其他东西。
以下是 Apple 关于可以存储在默认值中的对象类型的规定
还有一些更多的注意事项,例如如果您存储 NSDictionary,则键值必须是字符串。
Best and easiest way to store settings in the iPhone is through
NSUserDefaults
. Keeps you from having to deal with the file system or plists or any of that other stuff.Here's what Apple says on the types of objects you can store in the Defaults
There are some more caveats, like if you store an NSDictionary the key values must be strings.
如果您正在寻找可在应用程序内部编辑设置的 UI,请查看 InAppSettingsKit,网址为 http://www.inappsettingskit .com
If you're looking for a UI to edit the settings from inside the app, check out InAppSettingsKit at http://www.inappsettingskit.com
阅读来自 iPhone 开发者连接的文件和网络指南。它将解释如何获取应用程序沙箱中不同预定义位置的路径。我建议您使用 NSDictionary 来存储您的首选项,它可以轻松保存到文件系统并转换为 plist。
Read the File and Networking Guide from the iPhone Developer Connection. It will explain how you get the path for the different predefined locations in the application sandbox. I'd recommend that you use a NSDictionary to store your preferences which can easily be saved to the file system and converted into a plist.