Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First off, as mentioned by others here, <code>applicationDidEnterBackground:</code> is probably a better place to do this. Secondly, your view controller isn't going to get this call all on it's own: it's a <code>UIApplicationDelegate</code> protocol call, and your view controller isn't one of those.</p> <p>What you want to do is make your view controller receive the <code>UIApplicationDidEnterBackgroundNotification</code> notification. <a href="https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/applicationDidEnterBackground%3a" rel="nofollow">The UIApplicationDelegate reference</a> says:</p> <blockquote> <p>The application also posts a UIApplicationDidEnterBackgroundNotification notification around the same time it calls this method to give interested objects a chance to respond to the transition.</p> </blockquote> <p>So in your view controller you want to do something like this (warning: typed this code right into the webpage, didn't try to compile it):</p> <pre><code>- (void) viewDidLoad { [super viewDidLoad]; // Register for notification. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil]; } - (void) viewDidUnload { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void) applicationDidEnterBackground:(NSNotification*)notification { // Do your plist saving here. } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload