Inside iPhone Application Bundles
With iTunes now shipping the first ever iPod touch application (the property list that unlocks the built-in applications and 1.1.3 firmware features), I thought I might take the opportunity to describe the way an iPhone application works. If you're familiar with Macintosh application bundles, you'll find that the iPhone application is similar...yet different.
Like its Macintosh cousin, the iPhone application lives in an Application bundle, a folder using the .app extension. All the application's contents and resources live in this folder and are treated by the operating system as a single bundle. To create an iPhone "application", you simply create a folder named with the app extension and fill it with the executable, the supporting media including images and sounds and a few special files that describe the application to the OS.
Unlike the Mac, however, the iPhone bundle does not use Contents and Resources folders to store its data. All materials are placed at the top level of the folder. So instead of putting a language support .lproj folder into Contents/Resources, the folder is placed directly into the .app folder. Yes, you can still use subfolders to organize your project, but these are user defined and not standard. The iPhone includes NSBundle support making it easy to find your application's root folder and to navigate down to your custom subfolders to find those resources.
The actual executable therefore goes directly into the top level of your folder. And, like the Macintosh, the iPhone application contains that all important Info.plist file. Info.plist defines and describes the application. In it you specify the application's executable (CFBundleExecutable) and identifier (CFBundleIdentifier). This latter, the identifier, is critical to proper behavior and execution. I use the standard (albeit a little silly) Apple naming format (com.sadun.whatever) in all my applications. The identifier allows you to communicate with other applications and to properly register your application with SpringBoard, the "Finder" of the iPhone. SpringBoard runs the home screen from which you launch your applications.
As with the Macintosh, the Info.plist file offers a lot of flexibility on the iPhone and when Apple releases its SDK documentation in February, I only expect this flexibility to grow. With it, you can set SpringBoard variables (e.g. SBIconClass, and SBUsesNetwork) and define multiple roles for a single application (for example, the Photos and Camera utilities are both actually the same application, MobileSlideShow, playing separate "roles").
You can include a PkgInfo file with your iPhone application although at this time it doesn't seem to do anything because there are no type definitions per se on the iPhone. So a simple 8-character APPL???? package file does the trick--and can be omitted from your .app bundle without any noticeable consequences.
Two key image files are icon.png and Default.png. Icon.png, usually 58x58 pixels in size (I'm still waiting for the official word from Apple on sizing) is the image used to show the application on SpringBoard. Default.png displays during the launch of your application. You can use it to splash a logo or to display a "Please wait..." message.
As with the Macintosh, things you do not find inside the application bundle include preferences files (generally stored in ~/Library/Preferences) and application plug-ins (stored in /System/Library at this time).
Another thing that seems to be missing (at least from the Macintosh programmer point of view) is Application Support folders. Independent developers have been creating their own folders at this time, in ~/Library or ~/Media, which more rightfully would be placed into an Application Support structure. Only time will tell if Apple promotes this for iPhone development.
Categories
MacComments (0)
Read More Entries by Erica Sadun.

Leave a comment