Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's how to listen for such events:</p> <pre><code>// Register for notification when the app shuts down [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myFunc) name:UIApplicationWillTerminateNotification object:nil]; // On iOS 4.0+ only, listen for background notification if(&amp;UIApplicationDidEnterBackgroundNotification != nil) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myFunc) name:UIApplicationDidEnterBackgroundNotification object:nil]; } // On iOS 4.0+ only, listen for foreground notification if(&amp;UIApplicationWillEnterForegroundNotification != nil) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myFunc) name:UIApplicationWillEnterForegroundNotification object:nil]; } </code></pre> <p>Note: The <code>if(&amp;SomeSymbol)</code> checks ensure that your code will work on iOS 4.0+ and also on iOS 3.x - if you build against an iOS 4.x or 5.x SDK and set the deployment target to iOS 3.x your app can still run on 3.x devices but the address of relevant symbols will be nil, and therefore it won't try to ask for notifications that don't exist on 3.x devices (which would crash the app).</p> <p><strong>Update:</strong> In this case, the <code>if(&amp;Symbol)</code> checks are now redundant (unless you <em>really</em> need to support iOS 3 for some reason). However, it's useful to know this technique for checking if an API exists before using it. I prefer this technique than testing the OS version because you are checking if the specific API is present rather than using outside knowledge of what APIs are present in what OS versions.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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