Update Your App for Multitasking with iOS 4 By Craig Hockenberry
Anyone with programming experience can learn how to write an iPhone app. But if you want to build a great app, there's a lot more to it than simple coding: you also need to know how design and market your creation. This easy-to-follow guide walks you through the entire process, from sketching out your idea to promoting the finished product.
- Get to know the tools for developing your iPhone app
- Design a great app before you start coding
- Build a complex app with Xcode and Interface Builder
- Decide how to brand your app-then beta-test that brand in the real world
- Learn the inside scoop on how to get your app into the App Store
- Promote your product, track sales, and build a strong customer following
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 Apple’s iPhone Dev Center. 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:
1. Open your iPhone app project in the new version of Xcode, and then choose Project > Edit Project Settings to update your project settings.
2. In the General tab, change the Base SDK for All Configurations from “iPhone Device 3.0 (missing)” to “iPhone Device 4.0.”
3. In the Build tab, set the Configuration to “Release” and enter a search for “target.”
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.