updating settings from within app in iphone 3.1 effective on re-launch of app - does not work in iOS4
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.
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:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleChangeInUserSettings:) name:NSUserDefaultsDidChangeNotification object:nil];
where -handleChangeInUserSettings:
is a method where you perform the updates needed to reflect the changed user settings.
精彩评论