iOS introduced support for multitasking in version 4. Multitasking in iOS is straightforward, with simple rules that give the user a great experience while allowing applications to multitask with ease. Not all iOS devices support multitasking, as you will learn in Recipe 11.1.
Multitasking enables background execution, which means the application can keep working as usual—running tasks, spawning new threads, listening for notifications, and reacting to events—but simply does not display anything on the screen or have any way to interact with the user. When the user presses the Home button on the device, which in previous versions of the iPhone and iPad would terminate the application, the application is now sent into the background.
An application running on an iOS version that supports multitasking is, by default, opted into background execution. If you link your application against iOS SDK 4.0 and later, you can opt out of background execution, as you will see in Recipe 11.11. If you do, your application will be terminated when the user presses the Home button, as before.
When our application moves to the background (such as when the user presses the Home button) and then back to the foreground (when the user selects the application again), various messages are sent by the system and are expected to be received by an object we designate as our application delegate. For instance, when our application is sent to the background, our application ...