应用程序首选项只能在启动时读取吗?
我已经实现了 inappsettings 以获得首选项视图在我的应用程序中能够直接在应用程序中编辑 settings.bundle 值。
但是现在我想从 settings.bundle 中读取内容,但读取 iOS 编程指南 我发现settings.bundle 应该在应用程序启动时读取。
那么在我的代码中是否无法随时访问此首选项?如果用户在应用程序运行时无法随时更新首选项,则 Inappsettings 没有任何意义。
Inappsettings 提供了方法 InAppSettings registerDefaults
- (void)initialize{
if([self class] == [AppDelegate class]){
[InAppSettings registerDefaults];
}
}
但我不确定这是否可行随时阅读偏好设置。有什么建议吗?
编辑:在我的应用程序中,我有三个视图,一个是仪表板。另一个选项和邮件视图以模态方式显示。
在首选项中,用户可以设置发送消息所需的一些基本内容。因此,当用户刚刚开始打字并想要更改例如传输网关时,他会打开选项视图(即 inappsettings 视图)并更改一些内容。我想在不重新启动应用程序的情况下阅读此更改。
I have implemented inappsettings to have a preferences view in my application to be able to edit settings.bundle values straight in the app.
However now I wanted to read from settings.bundle but reading the iOS programming guide I found out that settings.bundle should be read on application startup.
So is it not possible to access this preferences any time in my code? Inappsettings would not make any sense if the user could not update preferences any time while the app is running.
Inappsettings offers the method InAppSettings registerDefaults
- (void)initialize{
if([self class] == [AppDelegate class]){
[InAppSettings registerDefaults];
}
}
But I am not sure if that makes it possible to read preferences any time. Any suggestions?
Edit: in my app I have three views, one is the dashboard. The other, a option and a mail view, are shown modally.
In the preferences the user can setup some basic things that I need to send the message. So when the user just started typing and wants to change e.g. the transmission gateway he opens the option view, which is the inappsettings view, and changes some things. I would like to read this changes without restarting the app.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显然,苹果希望将外部偏好 UI 范式强加给我们。请回忆一下 Mail.app 的工作原理。有时这种范式有意义,有时则不然。如果你有不可变的首选项集,你就不必考虑事件处理 onPrefferenceChange、并发、同步、操作系统备份和复制问题等……但是,Apple 提供的功能非常有限。您甚至不能在那里输入任意字符串(Mail.app 显然为此使用了一些私有 API)。因此,您必须做出选择,是否可以使用 Apple 提供的内容或实现您自己的偏好系统(可能基于
NSUSerDefaults
或其他内容)。我自己实现过一次,从那以后我就一直使用它。我更喜欢有一个真正的应用内偏好系统。其主要优点是能够在不离开应用程序的情况下更改其值。Clearly Apple wants to impose external preferences UI paradigm on us. Please recall how Mail.app works. Sometimes that paradigm makes sense, sometimes doesn't. If you have immutable preference set, you don't have to think about events handling onPrefferenceChange, concurrency, synchronization, OS backup and replication issues,etc... However the facilities that Apple provided are very limited in what they can do. You can't even enter an arbitrary string there (Mail.app clearly uses some private API for that). So you have to make a choice whether you can use what Apple offers or implement your own preference system (may be based on top of
NSUSerDefaults
or something). I implemented my own once and I use it ever since. I prefer to have a real in-app preference system. The main advantage of that is to able changing its value without leaving an app.