更新应用程序时如何处理偏好设置?
当我更新应用程序时,有些人抱怨首选项失败。当用户第一次启动更新时,如何“重置”首选项?
When I do an update of my app, some people complain the preferences fail. How can I 'reset' the preferences when the user launches an update for the first time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种方法是包含一个首选项,指示上次更新首选项的应用程序版本。然后,当您更新的应用程序首次运行时,它可以检查该首选项值,查看它是否较旧,并对现有首选项执行任何必要的更新。
One method would be to include a preference that indicates the version of the app that last updated the preferences. Then, when your updated applications is first run, it can check that preference value, see that it is older, and perform whatever updates to the existing preferences are necessary.
尽管我认为这不是一个好的做法:您可以在包含所使用的应用程序版本的首选项中保留一个密钥,并在每次应用程序启动时检查此密钥。如果密钥的编号低于当前应用程序的编号,请调用
[NSUserDefaults resetStandardUserDefaults]
Although I don't think this is good practice: You can keep a key in your preferences containing the app version it was used with and check this key each app launch. If the key's number is lower than your current application's number, call
[NSUserDefaults resetStandardUserDefaults]