concept background in category ios

appears as: background, background
iOS 4 in Action: Developing iPhone and iPad Apps

This is an excerpt from Manning's book iOS 4 in Action: Developing iPhone and iPad Apps.

Imagine a program that uses an image as a background, sets up a web view on top of that, and has a label running above everything. We’ll show you how easy it is to create those entirely usable objects in Interface Builder.

iOS 4 is muscled up with tons of exciting new features. We’ve covered the Game Kit framework, local notifications, the Event Kit framework, GCD, and iAd in previous chapters. In this chapter, it’s time to introduce multitasking! Multitasking is a feature that has been requested on iOS since its first release. But there’s limited screen size and battery life on the iPhone or iPad, so generally only one application is visible and active at a time. In iOS 4 and later, with multitasking introduced, applications can continue running in the background.

What’s multitasking? It’s one of the important and exciting API features in iOS 4. When the user quits an application, instead of terminating, the application will enter the background state; you can use this feature to support fast app switching and running tasks in the background.

In this chapter, we’ll first cover the multitasking basics, the application’s lifecycle on iOS 4, followed by the background state and best practices based on an app’s lifecycle transitions. Then we’ll talk about how to adopt fast app switching on the iPhone and iPad and how to update the application interface with the correct user data when the application gets restarted from the background state. Finally, we’ll use a demo app to explain how to finish a task in the background with an expiration handler. First, let’s explore some basics on multitasking.

Listing 21.3 is an example of a task-completion API, showing how to finish a task in the background before the applications gets suspended. You can create a window-based project from the iOS template project in Xcode, because this part of API will only make changes to the app delegate file. In the app delegate header file, add in the task identifier: UIBackgroundTaskIdentifier bgTask. Define bgTask as a property of the app delegate, and synthesize it in the.m file.

Listing 21.3. Task completion in the background