applicationWillTerminate works as long as I don't switch off the iPhone
<p>to save some variables of my apps I use:</p>

<p>-(void)applicationWillTerminate:(UIApplication *)application {</p>

<pre><code>NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setFloat: self.viewController.sLabel.contentOffset.y forKey:@"floatKey"]; 
[prefs setObject:self.viewController.newText forKey:@"stringVal"];
[prefs synchronize];
</code></pre>

<p>}</p>

<p>and to retrieve them, via a button, I do the following:</p>

<p>-(IBAction) riprendi:(id) sender {</p>

<pre><code>NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; 
float myFloat = [prefs floatForKey:@"floatKey"];
</code></pre>

<p>//some actions here</p>

<p>}</p>

<p>Everything is working on the simulator. However, using it on a real iPhone, the variables' saving and retrieving works just if you press the Home button, exiting the app and opening again but NOT if you switch off/on the iPhone. In this case, the variables get simply lost once you re-open the app...</p>

<p>What am I missing?? This is actually driving me crazy :(</p>

<p>Thank you so much ;)
Fabio</p>
