Another SDK and more changes. Woo hoo! What are the changes for programmers? What new things and goodies did Apple add for us to discover. 😉 – Jack
iPhone OS 4.0
This article summarizes the developer-related features introduced in iPhone OS 4.0. This version of the operating system runs on iPhone and iPod touch only and does not run on iPad. In addition to describing the new features, this article lists the documents that describe those features in more detail.
For the latest updates and information, you should also see iPhone OS 4.0 Release Notes. For the list of API differences between the iPhone OS 4.0 and earlier versions of iPhone OS, see iPhone OS 4.0 API Diffs.
Applications built using iPhone SDK 4.0 or later (and running in iPhone OS 4.0 and later) are no longer terminated when the user presses the Home button; instead, they now shift to a background execution context. For many applications, this means that the application enters a suspended state of execution shortly after entering the background. Keeping the application in memory avoids the subsequent launch cycle and allows an application to simply reactivate itself, which improves the overall user experience. And suspending the application improves overall system performance by minimizing power usage and giving more execution time to the foreground application.
Although most applications are suspended shortly after moving to the background, applications that need to continue working in the background may do so using one of the following techniques:
- 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 some additional work on your part. Background applications can still be terminated under certain conditions (such as during low-memory conditions), and so applications must be ready to exit at any time. This means that many of the tasks you used to perform at quit time must now be performed when your application moves to the background. This requires implementing some new methods in your application delegate to respond to application state transitions.
The following sections describe the technologies you can use to enhance your applicationâ€™s user experience.
Local notifications complement the existing push notifications by giving applications an avenue for generating the notifications locally instead of relying on an external server. Background applications 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.
The Event Kit framework (
EventKit.framework) provides an interface for accessing calendar events on a userâ€™s device. You can use this framework to get existing events and add new events to the userâ€™s calendar. Calendar events can include alarms that you can configure with rules for when they should be delivered. In addition to using Event Kit for creating new events, you can use the view controllers of the Event Kit UI framework (
EventKitUI.framework) to present standard system interfaces for viewing and editing events.
Applications that work with sensitive user data can now take advantage of the built-in encryption available on some devices to protect that data. When your application designates a particular file as protected, the system stores that file on-disk in an encrypted format. While the device is locked, the contents of the file are inaccessible to both your application and to any potential intruders. However, when the device is unlocked by the user, a decryption key is created to allow your application to access the file.
Implementing data protection requires you to be considerate in how you create and manage the data you want to protect. Applications must themselves be designed to secure the data at creation time and to be prepared for changes in access to that data when the user locks and unlocks the device.
The Core Telephony framework (
CoreTelephony.framework) provides interfaces for interacting with phone-based information on devices that have a cellular radio. Applications can use this framework to get information about a userâ€™s cellular service provider. Applications interested in cellular call events can also be notified when those events occur.
You can use iAd (
AdLib.framework) to deliver modal advertisements (also known as interstitial advertisements) and 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.
Graphics and Multimedia
The following sections describe the new graphics and media-related technologies you can incorporate into your applications.
Quick Look Framework
The Quick Look framework (
QuickLook.framework) provides a direct interface for previewing the contents of files your application does not support directly. This framework is intended primarily for applications that download files from the network or that otherwise work with files from unknown sources. After obtaining the file, you use the view controller provided by this framework to display the contents of that file directly in your user interface.
The AV Foundation framework (
AVFoundation.framework) is for applications that need to go beyond the music and movie playback features found in the Media Player framework. Originally introduced in iPhone OS 3.0, this framework has been expanded in iPhone OS 4.0 to include significant new capabilities, substantially broadening its usage beyond basic audio playback and recording capabilities. Specifically, this framework now includes support for the following features:
- Media asset management
- Media editing
- Movie capture
- Movie playback
- Track management
- Metadata management for media items
The AV Foundation framework is a single source for recording and playing back audio and video in iPhone OS. This framework also provides much more sophisticated support for handling and managing media items.
The Assets Library framework (
AssetsLibrary.framework) provides a query-based interface for retrieving a userâ€™s photos and videos. Using this framework, you can access the same assets that are nominally managed by the Photos application, including items in the userâ€™s saved photos album and any photos and videos that were imported onto the device. You can also save new photos and videos back to the userâ€™s saved photos album.
The Image I/O framework (
ImageIO.framework) provides interfaces for importing and exporting image data and image metadata. This framework is built on top of the Core Graphics data types and functions and supports all of the standard image types available in iPhone OS.
The Core Media framework (
CoreMedia.framework) provides the low-level media types used by AV Foundation. Most applications should never need to use this framework, but it is provided for those few developers who need more precise control over the creation and presentation of audio and video content.
The Core Video framework (
CoreVideo.framework) provides buffer and buffer pool support for Core Media. Most applications should never need to use this framework directly.
The following sections describe the new lower-level technologies and features you can incorporate into your applications.
Block objects are a C-level language construct that you can incorporate into your C, C++, and Objective-C code. A block object is a mechanism for creating an ad hoc function body, something which in other languages is sometimes called a closure or lambda. You use block objects in places where you need to create a reusable segment of code but where creating a function or method might be too heavyweight or inflexible.
In iPhone OS, blocks are commonly used in the following scenarios:
- As a replacement for delegates and delegate methods
- As a replacement for callback functions
- To implement completion handlers for one-time operations
- To facilitate performing a task on all the items in a collection
- Together with dispatch queues, to perform asynchronous tasks
Grand Central Dispatch
Grand Central Dispatch (GCD) is a BSD-level technology that you use to manage the execution of tasks in your application. GCD combines an asynchronous programming model with a highly optimized core to provide a convenient (and more efficient) alternative to threading. GCD also provides convenient alternatives for many types of low-level tasks, such as reading and writing file descriptors, implementing timers, monitoring signals and process events, and more.
The Accelerate framework (
Accelerate.framework) contains interfaces for performing math, big-number, and DSP calculations, among others. The advantage of using this framework over writing your own versions of these libraries is that it is optimized for the different hardware configurations present in iPhone OSâ€“based devices. Therefore, you can write your code once and be assured that it runs efficiently on all devices.
UI Automation API
Additional Framework Enhancements
The following frameworks and technologies include additional incremental changes. For a complete list of new interfaces, see iPhone OS 4.0 API Diffs.
UIKit Framework Enhancements
The UIKit framework includes the following enhancements:
UIApplicationDelegateprotocol include new methods for scheduling local notifications and for supporting multitasking.
- Drawing to a graphics context in UIKit is now thread-safe. Specifically:
- The routines used to access and manipulate the graphics context can now correctly handle contexts residing on different threads.
- String and image drawing is now thread-safe.
- Using color and font objects in multiple threads is now safe to do.
UIImagePickerControllerclass includes methods for programmatically starting and stopping video capture.
UILocalNotificationclass supports the configuration of local notifications; see â€œLocal Notifications.â€
UIViewclass includes new block-based methods for implementing animations.
UIWindowclass has a new
rootViewControllerproperty that you can use to change the contents of the window.
- Media applications can now receive events related to the controls on an attached set of headphones. You can use these events to control the playback of media-related items.
- Several new accessibility interfaces help you make some UI elements more accessible and allow you to customize your application experience specifically for VoiceOver users:
UIAccessibilityActionprotocol makes it easy for VoiceOver users to adjust the value of UI elements, such as pickers and sliders.
UIPickerViewAccessibilityDelegateprotocol enables access to the individual components of a picker.
UIAccessibilityFocusprotocol allows you to find out when VoiceOver is focused on an element, so you can help users avoid making unnecessary taps.
UIAccessibilityTraitStartsMediaSessiontrait allows you to prevent VoiceOver from speaking during a media session that should not be interrupted.
- New interfaces in
UIAccessibility Protocolprotocol allow you to specify the language in which labels and hints are spoken, and provide announcements that describe events that don’t update application UI in way that would be perceptible to VoiceOver users.
UINibclass provides a way to instantiate multiple sets of objects efficiently from the same nib file.
Foundation Framework Enhancements
The Foundation framework includes the following enhancements:
- Most delegate methods are now declared in formal protocols instead of as categories on
- Block-based variants are now available for many types of operations.
- There is new support for creating and formatting date information in
NSDateComponentsclass added support for specifying time zone and quarter information.
- There is support for regular-expression matching using the
NSBlockOperationclass allows you to add blocks to operation queues.
- You can use the
NSFileManagerclass to mark files as protected;
NSFileWrapperclass allows you to work with package-based document types.
NSOrthographyclass describes the linguistic content of a piece of text.
NSCacheclass provides support for storing and managing temporary data.
- The URL-related classes have been updated so that you can now pipeline URL requests and set request priorities.
Game Kit Enhancements
The Game Kit framework includes a beta implementation of a centralized service called Game Center. This service provides game developers with a standard way to implement the following features:
- Aliases 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.
- Leader boards allow your application to post scores to Game Center and retrieve them later.
- Matchmaking allows players to connect with other players with Game Center accounts.
Core Location Enhancements
The Core Location framework now includes a new location monitoring service that offers a lower-power alternative for determining the userâ€™s location.
Map Kit Enhancements
The Map Kit framework includes the following enhancements:
- Support for draggable map annotations
- Support for map overlays
Draggable map annotations make it much easier to reposition those annotations after they have been added to a map. The Map Kit framework handles most of the touch events associated with initiating, tracking, and ending a drag operation. However, the annotation view must work in conjunction with the map view delegate to ensure that dragging of the annotation view is supported.
Map overlays provide a way to create more complex types of annotations. Instead of being pinned to a single point, an overlay can represent a path or shape that spans a wider region. You can use overlays to layer information such as bus routes, election maps, park boundaries, and weather maps on top of the map.
Message UI Enhancements
The Message UI framework includes a new
MFMessageComposeViewController class for composing SMS messages. This class manages a standard system interface for composing and sending SMS messages. In contrast with sending SMS messages using a specially formatted URL, this class allows you to create and send the message entirely from within your application.
Core Graphics Enhancements
The Core Graphics framework includes the following enhancements:
- The ability to embed metadata into PDF files using the
- Support for creating color spaces using an ICC profile
- Graphics context support for font smoothing and fine-grained pixel manipulation
The International Components for Unicode (ICU) libraries were updated to version 4.4. ICU is an open-source project for Unicode support and software internationalization. The installed version of ICU includes only a subset of the header files that are part of the broader ICU library. Specifically, iPhone OS includes only the headers used to support regular expressions.
Although iPhone OS 3.2 does not run on iPhone and iPod touch devices, many of the features introduced in that version of the operating system are also supported in iPhone OS 4.0. Specifically, iPhone OS 4.0 supports:
- Custom input views
- Connecting external displays
- File-sharing support
- Gesture recognizers
- Core Text for text layout and rendering
- Text input through integration with the keyboard
- Custom fonts
- ICU Regular Expressions
- Document types
- PDF generation
- Xcode Tools changes
- UIKit framework changes
- Media Player framework changes
- Core Animation changes
- Foundation framework changes
What is not supported are new controls and classes designed specifically for iPad.