Application Lifetime Events

As I’ve already mentioned, events mark certain important stages in the overall lifetime of your application. These events can arrive either as messages to the app delegate (if you implement the appropriate methods) or as notifications to any object (if that object registers for those notifications).

In the old days, before iOS 4, this suite of events was pretty simple:

applicationDidFinishLaunching:
The app has started up. This, as we have already seen many times, is the earliest opportunity for your code to configure the interface by showing the app’s window. (For reasons that we haven’t yet discussed, it is now better for your app delegate to implement application:didFinishLaunchingWithOptions: instead.)
applicationDidBecomeActive:
The app has started up; received after applicationDidFinishLaunching:. Also received after the end of the situation that caused the app delegate to receive applicationWillResignActive:.
applicationWillResignActive:
Something has blocked the app’s interface. The most common cause is that the screen has been locked. An alert from outside your app could also cause this event.
applicationWillTerminate:
The app is about to quit. This is your last signal to preserve state (typically, by storing information with NSUserDefaults) and perform other final cleanup tasks.

Starting with iOS 4, however, apps operate in a multitasking environment. The Home button doesn’t terminate your app; it suspends it. This means that your app ...

Get Programming iOS 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.