从 iPhone 3.1 中的应用程序内更新设置在重新启动应用程序时生效 - 在 iOS4 中不起作用
我正在为 iphone OS 3.1 开发一个应用程序。在应用程序中,我有“设置”选项卡,用户可以在其中更新一些在应用程序终止和重新启动时有效的值。
我现在已经构建了这个应用程序,并将 Base SDK 设置为“Device 4.0”,并将部署目标设置为“iOS 3.1”,因为我不想失去 iOS 3.1 用户群。
在 iphone 模拟器 3.2 上运行这个版本的应用程序,我没有任何问题。
为了测试该应用程序是否适用于 iPhone OS 3.1 已升级到 iOS4 的情况,我在设备“iPhone”上运行此版本,在 iPhone 模拟器中运行版本“4.0”。由于 iOS4 中的应用程序多任务处理,当我按下“主页”按钮时,我的应用程序不会“终止”,而是(如预期)它进入后台并按下应用程序图标,它会返回前台。
所有这一切都很好,当用户更改应用程序内的设置中的某些内容时,就会出现问题,按“home”不会终止应用程序......因此新设置将不会生效,因为应用程序不会重新启动启动但只会返回到“前台”......事实上,除非用户专门终止该应用程序,否则该应用程序可能永远不会终止。
如果不使用 iOS4 API,我如何识别应用程序何时“重新启动”以及何时进入“前台”,以便我可以在应用程序移至“前台”时强制重新读取设置?
提前致谢。
I am working on an App for iphone OS 3.1. In the app I have 'settings' tab where user can update some values which are effective when the app terminates and re-launches.
I have now built this app with Base SDK set to 'Device 4.0' and the deployment target to 'iOS 3.1', since I do not want to loose the iOS 3.1 user base.
Running this version of the app on iphone simulator 3.2, I do not have any issues.
To test the app for the situation where an iPhone OS 3.1 has been upgraded to iOS4, I run this version on Device 'iPhone' and Version '4.0' in iphone Simulator. Due to Application Multitasking in iOS4, my app does not 'terminate' when I press the 'Home' button, instead (as expected) it goes in the background and pressing the app icon, it comes back to foreground.
All this is fine, the issue arrises when the user changes something in the settings within the app, pressing the 'home' will not terminate the app....and hence the new settings will not be effective as the app will not re-launch but will only be coming back in the 'foreground' .... in fact the app may never terminate unless user specifically terminates the app.
Without using the iOS4 APIs how do I identify when the app is 're-launched' and when it is coming in 'foreground', so that I may force the settings to be re-read when app is moving in 'foreground'?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了在后台处理应用程序设置的更改,您需要侦听 NSUserDefaultsDidChangeNotification 并通过更新受更改设置影响的应用程序部分来响应它。当您的应用程序重新进入前台时,如果应用程序的任何设置在暂停期间发生更改,它将收到此通知。
例如,您可以使用如下代码在一个控制器中侦听此通知:
其中
-handleChangeInUserSettings:
是一种执行反映更改的用户设置所需的更新的方法。In order to handle changes in the settings for your application while in the background, you will want to listen for
NSUserDefaultsDidChangeNotification
and respond to it by updating the portions of your application affected by the changed settings. When your application reenters the foreground, it will receive this notification if any of the settings for the application have changed while it was suspended.For example, you can listen for this notification in one of your controllers using code like the following:
where
-handleChangeInUserSettings:
is a method where you perform the updates needed to reflect the changed user settings.