Jump to content

How to Update Your iPhone App for Multitasking with iOS 4

+ 2
  chco's Photo
Posted Aug 04 2010 07:55 AM

The following is a new tip from Craig Hockenberry, author of iPhone App Development: The Missing Manual, that explains how to enable multitasking in your iPhone OS 3 apps.
On multitasking phones like the iPhone 3GS and iPhone 4, you can make it so your application doesn’t quit when the user presses the Home button. Instead, the app just goes into the background and reappears just as it was with a tap on its icon. You can give your app multitasking powers without writing a single line of code!

First, download and install the free iOS 4 SDK from http://developer.apple.com/iphone. You need both Xcode 3.2.3 and iPhone SDK 4 to create an app for iOS 4. (By the way, you may see the SDK described as either “iOS SDK” and “iPhone SDK.” They mean the same thing.)

Now you’re just a few steps away from a multitasking app:

  • Open your iPhone app project in the new version of Xcode, and then choose Project -> Edit Project Settings to update your project settings.

  • In the General tab, change the Base SDK for All Configurations from “iPhone Device 3.0 (missing)” to “iPhone Device 4.0.”

    Attached Image

  • In the Build tab, set the Configuration to “Release” and enter a search for “target.”

    Attached Image


You should now see the following:

  • In the Architecture section, the “Base SDK” setting is now “iPhone Device 4.0,” which means that Xcode will build your app with the iOS 4.0 SDK.

  • In the Deployment section, you'll see “iPhone OS Deployment Target.” This setting defines the oldest version of the iPhone OS where you want your app to be able to run. If your app used to run on version 3.0, you can change this setting to “iPhone OS 3.0.”


Now you can build your app in the usual way and test it on an iPhone.

You may want to make one further refinement, since the iPhone may terminate multitasking apps when the OS or another app needs more memory. To reduce the chances of your app getting purged from memory, clear out any caches or other data that can easily be reconstructed. Luckily, the system notifies your app when it puts the app into the background: that’s your chance to clear out this temporary memory. It’s also a good time to save any state or other information that you’ll use the next time your application is launched.

You can capture the notification in one of two ways: through a -applicationDidEnterBackground: method in your application delegate or by registering for the UIApplicationDidEnterBackgroundNotification in your view controllers. If you’re saving application-wide information, the delegate is the best choice. If you need to keep some of your controller’s model data, the notification is usually easier. You can use both techniques if necessary.

For more information on multitasking in iOS 4, check out “Supporting Multitasking In Your Applications” in the iPhone Dev Center.

Cover of iPhone App Development: The Missing Manual
Learn more about this topic from iPhone App Development: The Missing Manual. 

Ready to create your own iPhone app? This book walks you through the entire iPhone app development process. You'll learn how to download the tools, build the app, successfully navigate Apple's approval process, and then market and maintain the finished product. Written by Mac guru Craig Hockenberry, creator of the wildly popular Twitterific iPhone app, iPhone App Development: The Missing Manual includes illustrated, step-by-step tutorials and real-world examples.

Learn More Read Now on Safari


Tags:
1 Subscribe


1 Reply

 : Aug 05 2010 04:40 PM
All phones should jump to be iOS 4 compatible, but make sure you still support iOS 4 devices that are not capable of multi-tasking, and so forth. Follow best-practices.
------------------------------------------
Posted Image

Doron Katz
EMAIL: doron.e.katz@gmail.com
CELL: +61 (0) 410 740 678
FAX: +61 (0) 29904 3572

SKYPE: http://twitter.com/doronkatz
SKYPE: doronkatz1981
WWW: http://www.doronkatz.com