Chapter 38

Building Background-Aware Applications

Starting with iOS 4, Apple included support for background applications. If you have been building the applications in the Try It sections at the end of each lesson, you may have noticed that when you quit your application and launch it again from the home screen, your application resumes from where you left off. The reason for it is that projects created with Xcode 4.2 and above are background-ready by default.

Being background-ready does not mean that your application will run in the background. It just means that your application is aware of the support for background features in iOS and can take advantage of these features. In this lesson you learn how to create applications that can perform limited functions whilst in background mode.

Understanding Background Suspension

To support background execution, an application must be compiled against the iOS 4 SDK or higher. This means that if you purchase an application from the App Store that was created using an older version of the iOS SDK, the application will simply enter a suspended state of execution when you press the home button and will not be able to perform any background processing.

When a user quits a background-aware application by pressing the home button, the application is usually moved into a suspended state. Most applications cease to execute any code in this suspended state. Instead, these applications are preserved exactly as the user left them. When the user ...

Get iPhone and iPad App 24-Hour Trainer 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.