Cocoa Touch Layer
The Cocoa Touch layer contains the key frameworks for building iOS applications. This layer defines the basic application infrastructure and support for key technologies such as multitasking, touch-based input, push notifications, and many high-level system services. When designing your applications, you should investigate the technologies in this layer first to see if they meet your needs.
The following sections describe some of the key technologies available in the Cocoa Touch layer.
Introduced in iOS 6, auto layout improves upon the “springs and struts” model previously used to lay out the elements of a user interface. With auto layout, you define rules for how to lay out the elements in your user interface. These rules express a larger class of relationships and are more intuitive to use than springs and struts. For example, you can specify that a button should always be 20 points from the left edge of its parent view.
The entities used in Auto Layout are Objective-C objects called constraints. This approach brings you a number of benefits:
Localization through swapping of strings alone, instead of also revamping layouts.
Mirroring of user-interface elements for right-to-left languages like Hebrew and Arabic.
Better layering of responsibility between objects in the view and controller layers.
A view object usually knows best about its standard size, its positioning within its superview, and its positioning relative to its sibling views. A view controller can override these values if something nonstandard is required.
For more information about using auto layout, see Cocoa Auto Layout Guide.
Introduced in iOS 5, storyboards supplant nib files as the recommended way to design your application’s user interface. Unlike nib files, storyboards let you design your entire user interface in one place so you can see all of your views and view controllers and how they work together. An important part of storyboards is the ability to define segues, which are transitions from one view controller to another. Applications can define these transitions visually in Xcode or initiate them programmatically in Xcode. These transitions allow you to capture the flow of your user interface in addition to the content.
You can use a single storyboard file to store all of your application’s view controllers and views, or you can use multiple view storyboards to organize portions of your interface. At build time, Xcode takes the contents of the storyboard file and divides it up into discrete pieces that can be loaded individually for better performance. Your application never needs to manipulate these pieces directly, though. The UIKit framework provides convenience classes for accessing the contents of a storyboard from your code.
For more information about using storyboards to design your interface, see Xcode User Guide. For information about how to access storyboards from your code, see the UIStoryboard Class Reference.
Introduced in iOS 5, the UIKit framework introduced the
UIDocument class for managing the data associated with user documents. This class makes implementing document-based applications much easier, especially applications that store documents in iCloud. In addition to providing a container for all of your document-related data, the
UIDocument class provides built-in support for asynchronous reading and writing of file data, safe saving of data, automatic saving of data, support for detecting iCloud conflicts, and support for flat file or package file representations. For applications that use Core Data for their data model, you can use the
UIManagedDocument subclass to manage your data stores.
For information about using documents in your apps, see Document-Based App Programming Guide for iOS.
Applications built using iOS SDK 4.0 or later (and running in iOS 4.0 and later) are not terminated when the user presses the Home button; instead, they shift to a background execution context. The multitasking support defined by UIKit helps your application transition to and from the background state smoothly.
To preserve battery life, most applications are suspended by the system shortly after entering the background. A suspended application remains in memory but does not execute any code. This behavior allows an application to resume quickly when it is relaunched without consuming battery power in the meantime. However, applications may be allowed to continue running in the background for the following reasons:
An application can request a finite amount of time to complete some important task.
An application can declare itself as supporting specific services that require regular background execution time.
An application can use local notifications to generate user alerts at designated times, whether or not the application is running.
Regardless of whether your application is suspended or continues running in the background, supporting multitasking does require additional work on your part. The system notifies your application as it transitions to and from the background. These notification points are your cue to perform any important application tasks such as saving user data.
For more information on how to handle multitasking transitions, and for information on how to request background execution time, see iOS App Programming Guide.
Introduced in iOS 4.2, the UIKit printing support allows applications to send content wirelessly to nearby printers. For the most part, UIKit does all of the heavy lifting associated with printing. It manages the printing interfaces, works with your application to render the printable content, and handles the scheduling and execution of print jobs on the printer.
Print jobs submitted by your application are handed off to the printing system, which manages the actual printing process. Print jobs from all applications on a device are queued and printed on a first-come, first-served basis. Users can get the status of print jobs from the Print Center application and can even use that application to cancel print jobs. All other aspects of printing are handled for you automatically by the system.
For information about how to incorporate printing support into your applications, see “Printing” in Drawing and Printing Guide for iOS.
UI State Preservation
Introduced in iOS 6, state preservation makes it easier for apps to restore their user interface to the state it was in when the user last used it. When an app moves to the background, it is asked to save the semantic state of its views and view controllers. Upon relaunch, the app uses this state to restore its interface and make it seem as if the app had never quit. Support for state preservation is integrated into UIKit, which provides the infrastructure for saving and restoring your app’s interface.
For more information about how to add state preservation support to your app, see iOS App Programming Guide.
Apple Push Notification Service
Introduced in iOS 3.0, the Apple Push Notification Service provides a way to alert users of new information, even when your application is not actively running. Using this service, you can push text notifications, add a badge to your application icon, or trigger audible alerts on user devices at any time. These messages let users know that they should open your application to receive the related information.
From a design standpoint, there are two parts to making push notifications work for iOS applications. First, the application must request the delivery of notifications and process the notification data once it is delivered. Second, you need to provide a server-side process to generate the notifications in the first place. This process lives on your own local server and works with Apple Push Notification Service to trigger the notifications.
For more information about how to configure your application to use remote notifications, see Local and Push Notification Programming Guide.
Introduced in iOS 4.0, local notifications complement the existing push notification mechanism by giving applications an avenue for generating the notifications locally instead of relying on an external server. Applications running in the background can use local notifications as a way to get a user’s attention when important events happen. For example, a navigation application running in the background can use local notifications to alert the user when it is time to make a turn. Applications can also schedule the delivery of local notifications for a future date and time and have those notifications delivered even if the application is not running.
The advantage of local notifications is that they are independent of your application. Once a notification is scheduled, the system manages the delivery of it. Your application does not even have to be running when the notification is delivered.
For more information about using local notifications, see Local and Push Notification Programming Guide.
Introduced in iOS 3.2, gesture recognizers are objects that you attach to views and use to detect common types of gestures such as swipes and pinches. After attaching a gesture recognizer to your view, you tell it what action to perform when the gesture occurs. The gesture recognizer object then tracks the raw touch events and applies the system-defined heuristics for what the given gesture should be. Without gesture recognizers, you must do all this work yourself, which can be quite complicated.
UIKit includes a
UIGestureRecognizer class that defines the basic behavior for all gesture recognizers. You can define your own custom gesture recognizer subclasses or use one of the UIKit-supplied subclasses to handle any of the following standard gestures:
Tapping (any number of taps)
Pinching in and out (for zooming)
Panning or dragging
Swiping (in any direction)
Rotating (fingers moving in opposite directions)
For more information about the available gesture recognizers, see Event Handling Guide for iOS.
Introduced in iOS 3.0, the Game Kit framework provides peer-to-peer connectivity over Bluetooth. You can use peer-to-peer connectivity to initiate communication sessions with nearby devices and implement many of the features found in multiplayer games. Although primarily used in games, you can also use this feature in other types of applications.
For information about how to use peer-to-peer connectivity features in your application, see Game Center Programming Guide. For an overview of the Game Kit framework, see “Game Kit Framework.”
Standard System View Controllers
Many of the frameworks in the Cocoa Touch layer contain view controllers for presenting standard system interfaces. You are encouraged to use these view controllers in your applications to present a consistent user experience. Whenever you need to perform one of the following tasks, you should use a view controller from the corresponding framework:
Display or edit contact information—Use the view controllers in the Address Book UI framework.
Create or edit calendar events—Use the view controllers in the Event Kit UI framework.
Compose an email or SMS message—Use the view controllers in the Message UI framework.
Open or preview the contents of a file—Use the
UIDocumentInteractionControllerclass in the UIKit framework.
Take a picture or choose a photo from the user’s photo library—Use the
UIImagePickerControllerclass in the UIKit framework.
Shoot a video clip—Use the
UIImagePickerControllerclass in the UIKit framework.
For information on how to present and dismiss view controllers, see View Controller Programming Guide for iOS. For information about the interface presented by a specific view controller, see View Controller Catalog for iOS.
External Display Support
Introduced in iOS 3.2, external display support allows some iOS-based devices to be connected to an external display through a set of supported cables. When connected, the associated screen can be used by the application to display content. Information about the screen, including its supported resolutions, is accessible through the interfaces of the UIKit framework. You also use that framework to associate your application’s windows with one screen or another.
For more information about how to connect to, and display content on, an external display, see View Programming Guide for iOS.
Cocoa Touch Frameworks
The following sections describe the frameworks of the Cocoa Touch layer and the services they offer.
Address Book UI Framework
The Address Book UI framework (
AddressBookUI.framework) is an Objective-C programming interface that you use to display standard system interfaces for creating new contacts and for editing and selecting existing contacts. This framework simplifies the work needed to display contact information in your application and also ensures that your application uses the same interfaces as other applications, thus ensuring consistency across the platform.
For more information about the classes of the Address Book UI framework and how to use them, see Address Book Programming Guide for iOS and Address Book UI Framework Reference for iOS.
Event Kit UI Framework
Introduced in iOS 4.0, the Event Kit UI framework (
EventKitUI.framework) provides view controllers for presenting the standard system interfaces for viewing and editing calendar-related events. This framework builds upon the event-related data in the Event Kit framework, which is described in “Event Kit Framework.”
For more information about the classes and methods of this framework, see Event Kit UI Framework Reference.
Game Kit Framework
Introduced in iOS 3.0, the Game Kit framework (
GameKit.framework) lets you add peer-to-peer network capabilities to your applications. Specifically, this framework provides support for peer-to-peer connectivity and in-game voice features. Although these features are most commonly found in multiplayer network games, you can incorporate them into applications other than games as well. The framework provides networking features through a simple (yet powerful) set of classes built on top of Bonjour. These classes abstract out many of the network details. For developers who might be inexperienced with networking programming, the framework allows them to incorporate networking features into their applications.
Introduced in iOS 4.1, Game Center is an extension to the Game Kit framework that provides support for the following features:
Aliases, to allow users to create their own online persona. Users log in to Game Center and interact with other players anonymously through their alias. Players can set status messages as well as mark specific people as their friends.
Leaderboards, to allow your application to post user scores to Game Center and retrieve them later. You might use this feature to show the best scores among all users of your application.
Matchmaking, to allow you to create multiplayer games by connecting players who are logged into Game Center. Players do not have to be local to each other to join a multiplayer game.
Achievements, to allow you to record the progress a player has made in your game.
Challenges, allow a player to challenge a friend to beat an achievement or score. (iOS 6 and later)
In iOS 5 and later, you can use the
GKTurnBasedMatch class to implement support for turn-based gaming, which allows games to create persistent matches whose state is stored in iCloud. Your game manages the state information for the match and determines which player must act to advance the state of the match.
For more information about how to use the Game Kit framework, see Game Center Programming Guide and Game Kit Framework Reference.
Introduced in iOS 4.0, the iAd framework (
iAd.framework) lets you deliver banner-based advertisements from your application. Advertisements are incorporated into standard views that you integrate into your user interface and present when you want. The views themselves work with Apple’s ad service to automatically handle all the work associated with loading and presenting the ad content and responding to taps in those ads.
For more information about using iAd in your applications, see iAd Programming Guide and iAd Framework Reference.
Map Kit Framework
Introduced in iOS 3.0, the Map Kit framework (
MapKit.framework) provides a scrollable map interface that you can integrate into your existing view hierarchies. You can use this map to provide directions or highlight points of interest. Applications can programmatically set attributes of the map or let the user navigate the map freely. You can also annotate the map with custom images or content.
In iOS 4.0, the basic map view gained support for draggable annotations and custom overlays. Draggable annotations allow you to reposition an annotation, either programmatically or through user interactions, after it has been placed on the map. Overlays offer a way to create complex map annotations that comprise more than one point. For example, you can use overlays to layer information such as bus routes, election maps, park boundaries, or weather information (such as radar data) on top of the map.
In iOS 6.0, you can now create a routing app, whose job is to provide directions to users. When the user requests transit-related directions, the Maps app now lets the user choose the app from which to receive those directions. In addition, all apps can ask the Maps app to provide driving directions and display multiple points-of-interest.
For more information about using classes of the Map Kit framework, see Location Awareness Programming Guide and Map Kit Framework Reference.
Message UI Framework
Introduced in iOS 3.0, the Message UI framework (
MessageUI.framework) provides support for composing and queuing email messages in the user’s outbox. The composition support consists of a view controller interface that you present in your application. You can prepopulate the fields of this view controller to set the recipients, subject, body content, and any attachments you want to include with the message. After presenting the view controller, the user then has the option of editing the message prior to sending it.
In iOS 4.0 and later, this framework provides a view controller for presenting an SMS composition screen. You can use this view controller to create and edit SMS messages without leaving your application. As with the mail composition interface, this interface gives the user the option to edit the message before sending it.
For more information about the classes of the Message UI framework, see Message UI Framework Reference.
In iOS 6, the Twitter framework (
Twitter.framework) is replaced by the Social framework, which supports a UI for generating tweets and support for creating URLs to access the Twitter service. For more information about this framework, see “Social Framework.”
In iOS 5, you can use the Twitter framework (
Twitter.framework) to generate Twitter requests on behalf of the user and to composing and sending tweets. For information about the classes of the Twitter framework, see Twitter Framework Reference.
The UIKit framework (
UIKit.framework) provides the key infrastructure for implementing graphical, event-driven applications in iOS. Every iOS application uses this framework to implement the following core features:
User interface management, including support for storyboards and nib files
Graphics and windowing support, including support for multiple displays
Multitasking support; see “Multitasking”
Printing support; see “Printing”
Support for customizing the appearance of standard UIKit controls (iOS 5 and later)
Support for implementing view controllers that incorporate content from other view controllers (iOS 5 and later)
Support for handling touch and motion-based events
Objects representing the standard system views and controls
Support for text and web content
Cut, copy, and paste support
Support for animating user-interface content
Integration with other applications on the system through URL schemes and framework interfaces
Accessibility support for disabled users
Support for the Apple Push Notification Service; see “Apple Push Notification Service”
Local notification scheduling and delivery; see “Local Notifications”
Support for using custom input views that behave like the system keyboard
Support for creating custom text views that interact with the system keyboard
Support for sharing content through email, Twitter, Facebook, and other services
In addition to providing the fundamental code for building your application, UIKit also incorporates support for some device-specific features, such as the following:
The built-in camera (where present)
The user’s photo library
Device name and model information
Battery state information
Proximity sensor information
Remote-control information from attached headsets
For information about the classes of the UIKit framework, see UIKit Framework Reference.
© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-09-19)