iPhone OS Overview iPhone OS comprises the operating system and technologies that you use to run applications natively on iPhone and iPod touch devices. Although it shares a common heritage and many underlying technologies with Mac OS X, iPhone OS was designed to meet the needs of a mobile environment, where user’s needs are slightly different. Existing Mac OS X developers will find many familiar technologies, but they’ll also find technologies that are available only on iPhone OS, such as the Multi-Touch interface and accelerometer support. The iPhone SDK contains the code, information, and tools you need to develop, test, run, debug, and tune applications for the iPhone OS. The Xcode tools have been updated to support development for the iPhone OS. In addition to providing the basic editing, compilation, and debugging environment for your code, Xcode also provides the launching point for testing your applications on an iPhone or iPod touch device. Xcode also lets you run applications in iPhone simulator, a platform that mimics the basic iPhone OS environment on your local Macintosh computer. This article provides a high-level overview of the basic features found in iPhone OS, to help orient you to the platform. You’ll find other articles in the iPhone Dev Center to help get you up to speed quickly and to help you understand the basic process for creating iPhone applications. You should use these articles to help guide your learning path for iPhone OS. Figure 1 Figure 1 iPhone OS technology layers iPhone OS Technology Layers In iPhone OS, the underlying system architecture, and many of the technologies, are similar to those found in Mac OS X. The kernel in iPhone OS is based on a variant of the same basic Mach kernel that is found in Mac OS X. On top of this kernel are the layers of services that are used to implement applications on the platform. “Figure 1 iPhone OS technology layers” shows a high-level overview of these layers. Figure 2 iPhone OS technology layers This layering gives you choices when it comes to implementing your code. For example, the Core OS and Core Services layers contain the fundamental interfaces for iPhone OS, including those used for accessing files, low-level data types, Bonjour services, network sockets, and so on. These interfaces are mostly C-based and include technologies such as Core Foundation, CFNetwork, SQLite, and access to POSIX threads and UNIX sockets among others. As you move into the upper layers, you find more advanced technologies that use a mixture of C-based and Objective-C based interfaces. For example, the Media layer contains the fundamental technologies used to support 2D and 3D drawing, audio, and video. This layer includes the C-based technologies OpenGL ES, Quartz, and Core Audio. It also contains Core Animation, which is an advanced Objective-C based animation engine. In the Cocoa Touch layer, most of the technologies use Objective-C. The frameworks at these layers provide the fundamental infrastructure used by your application. For example, the Foundation framework provides object-oriented support for collections, file management, network operations, and more. The UIKit framework provides the visual infrastructure for your application, including classes for windows, views, controls, and the controllers that manage those objects. Other frameworks at this level give you access to the user’s contact and photo information and to the accelerometers and other hardware features of the device. The starting point for any new project is the Cocoa Touch layer, and the UIKit framework in particular. When deciding what additional technologies to use, it is recommended that you start with frameworks in the higher-level layers and fall back on the frameworks in the lower layers as needed. The higher-level frameworks make it easy to support standard system behaviors with the least amount of effort on your part. The only time you should fall back to the lower-level frameworks is when you want to implement custom behavior that is not provided at a higher level. For a more detailed overview of the technologies in iPhone OS, see iPhone OS Technology Overview. Writing Code for iPhone OS The iPhone SDK supports the creation of graphically-oriented applications that run natively in iPhone OS. The applications you create reside on the user’s Home screen, along with the other system applications, such as Photos, Weather, and Clock. After it is launched, aside from the kernel and a few low-level daemons, your application is the only application running on the system. While running, your application occupies the entire screen and is the focus of the user’s attention. And when the user presses the Home button, your application quits and the system displays the Home screen again. Having the system to yourself is advantageous because it gives you full access to the underlying system resources. You can take advantage of built-in hardware such as the accelerometers, camera, and graphics hardware to run just your code. Because the way users interact with iPhone and iPod touch devices is fundamentally different from the way users interact with Mac OS X, the way you design your applications must also be different. In an iPhone application, there is no concept of separate document windows for displaying content. Instead, all of the application’s data is displayed in a single window. This has lead to the creation of new views and controls that allow you to present your application’s data in an organized manner. In addition, many of the standard views and controls may behave a little differently than their Mac OS X counterparts. Most of these changes should be transparent but some may require you to rethink the way you organize and present your data. The event-handling model in iPhone OS also represents a significant departure from traditional desktop applications. Instead of relying on the traditional mouse and keyboard events, iPhone OS introduces the idea of touch events. A touch event can occur at any time and in combination with one or more additional touch events. Touches can be used to detect simple interactions with content, such as selecting or dragging items, or they can be used to detect complex gestures and interactions, such as swipes or the pinch-open and pinch-close gestures (used, for example, to zoom in and out in the Photos application). Beyond considering the basic structure of your application, you need to think about how users will actually use it. iPhone applications should be clean, and focused on what the user needs in the moment. Remember that users who are on-the-go want to get at information quickly and not spend a lot of time looking digging through several layers of screens. Providing a simple layout that highlights the key information the user needs is important. For games and other fun applications, you should also consider how the users might want to interact with your application and take advantage of technologies such as the accelerometers and camera where appropriate. As you start development, the frameworks you want to use initially are the Foundation and UIKit frameworks. These frameworks provide the key services used by all iPhone applications. As you refine your application, you should investigate the other frameworks in the system to see what services they offer. The documentation for each framework includes links to relevant conceptual materials to help you learn more about how to use that framework. For information about the Foundation and UIKit frameworks, see Foundation Framework Reference and UIKit Framework Reference. Where to Start Creating simple applications that run on iPhone OS is relatively easy with the built-in project templates provided by Xcode, but creating applications that do something useful and look nice requires you to spend some time reading through the available documentation. At a minimum, you should take the time to read through the other orientation articles in the iPhone Dev Center, which explore the tools and process for creating applications. If you are completely new to iPhone OS and to Mac OS X, taking the time to understand the basic design patterns and conventions of iPhone OS is critical to writing code for the platform. Applications operate best in iPhone OS when they take advantage of the power the frameworks provide. If you spend time trying to work around the basic framework behaviors, you may find creating your application much more difficult than simply learning the basic design patterns in use. The basic information that every iPhone developer needs to know is in Cocoa Fundamentals Guide. This document covers the basics of the Objective-C language and the programming conventions and design patterns used by UIKit and many other system frameworks. Once you understand the basic conventions you use to create iPhone applications, you can refer to iPhone Application Programming Guide for specific details on the development process. This book provides key conceptual and task-based information on how to write iPhone applications, including examples of how to display a user interface, handle events, and take advantage of key iPhone OS features. It also describes the overall development process and explains how you use Xcode to build and run your applications. In addition to iPhone Application Programming Guide, you should also look through the available sample code. iPhone OS ships with a number of full-featured samples that show you how to use the available technologies to create real-world applications. You can use these samples as a starting point for your own applications or you can look at them to learn more about how you use specific features.