Cocoa Touch Layer
The Cocoa Touch layer contains the key frameworks needed to create an iOS application. Up to implementing the application visual interface, down to interacting with advanced system services, requires that layer of technology provide the underlying foundation. When developing an application, try not to use the underlying framework as much as possible, and use the framework of that layer whenever possible.
Advanced Features
The following sections describe some common features, and perhaps you are also planning to support these features in your application.
Multi-tasking
If the application is built on iphone SDK 4.0 and its subsequent versions (and runs on iOS 4.0 and later versions of the operating system), when you click the Home button, the application does not end, but instead switches to the background. For most applications, entering the background, they go into a pending state. Having the application reside in the background avoids the subsequent restart process, which can be activated directly by the application, which greatly improves the overall user experience. Also, suspending an application can improve system performance because suspending an application minimizes power usage and allows the foreground application to get more execution time.
Although the application will be suspended in the background, the following techniques can be used to keep it running in the background:
Applications can request a certain amount of time to complete certain important tasks.
An application can declare that a service it supports needs to receive periodic background execution time.
Applications can use local advertisements to send notifications to users at a specified time. This approach is not required for the application to run.
Whether the application is suspended or running in the background, there is no additional work required to support multitasking. However, under certain circumstances, such as insufficient memory, the application may end up running. Therefore, the application should be able to exit at any time. This means that many of the tasks that need to be performed when exiting an application must be changed to execute when the application switches to the background. This requires that you implement some new methods in the application delegate in response to the state switch of the program.
If you need further information on how to handle background state switching and how to keep your application running in the background, check out the iOS application Programming Guide .
Data protection
Applications that work with sensitive user data can protect data using in-device encryption (some devices may not provide built-in encryption capabilities). If the application specifies that a file is protected, the file is saved to disk in an encrypted format. When the device is locked, your application and other potential intruders cannot access the file, and when the user unlocks the device, a key is generated so that your application can access the file.
For data protection, applications should do something about how to create and manage the data they want to protect. It must be able to secure it at the time the data is created, and it needs to adapt to changes in file accessibility caused by device lockout or unlocked.
To learn more about how your application adds data protection to your files, review the implementing standard Application behavior chapter in the iOS application Programming Guide .
Apple Push Notification Service
In IOS 3.0 and later versions of the system, the Apple push Notification Service can be used to notify the user that an application has new information, regardless of whether the application is running. With this service, you can push text notifications to the system, trigger a sound alert, or add a digitizing tag to the application icon. This allows users to know that they should open the application to receive relevant information.
From a design perspective, let the application support push notifications with two parts. First, the iOS application needs to ask the system to send a notification to it, and then it is reasonable to configure the application delegate so that it can properly handle the notification. These work can be done through application delegation and UIApplication
object collaboration. Second, you need to provide a server-side process to generate the initial notification. The process runs on your own local server, and it works with the Apple push Notification service to produce the initial notification.
For more information on how to configure your application to use remote notifications, see the local notification and push notification Programming Guide .
Local notifications
IOS 4.0 introduces a local notification. A local notification is a supplement to an existing push notification that can be generated locally by a generic program, eliminating the need to rely on an external server. When important events occur, background applications can take advantage of local notifications to gain user attention. For example, a navigation application running in the background can use local notifications to remind users to turn. The application can also schedule a local notification to be sent to the user at some point in the future, and sending these notifications does not require the application to be in a running state.
The advantage of local notifications is that it is independent of your application. Once a notification has been scheduled, the system will be responsible for sending notifications. And when you send a notification, your application doesn't need to be in a running state
For more information on how local notifications are used, see the local notification and push notification Programming Guide .
Gesture recognizer
IOS 3.2 introduces a gesture recognizer. A gesture recognizer is an object that is bound to a view to detect common gesture types. When you bind a gesture recognizer to a view, you can tell it what action to perform when a gesture occurs. The gesture recognizer can then track the original event and identify gestures based on system-defined heuristics. Before you introduce a gesture recognizer, if you want to recognize a gesture, you need to track the original touch event flow of the view, and then use a sophisticated heuristic to determine whether these events represent a gesture.
The Uikit framework now contains a UIGestureRecognizer
class that defines the basic behavior of all gesture recognizers. You can use a custom gesture recognizer subclass or a system-defined subclass to handle these standard gestures:
Spanking (any number of slaps)
Pinch inward or outward (for zooming)
Shaking or dragging
Rub (in any direction)
Rotate (move the finger in the opposite direction)
Long Press
To learn more about the gesture recognizer you can use, see the iOS Event handling guide .
File sharing support
Applications can use file shares to allow users to access programs ' user data files. File sharing allows applications to expose /Documents
the content of the application catalog to users through itunes. This allows users to move files back and forth on ipad and desktop computers. However, this feature does not allow applications to share files with other applications on the same device. If you want to share files between programs, use the Clipboard or the document interaction controller object.
You can use the following steps to enable your application to support file sharing:
Add a key to the application's Info.plist
file UIFileSharingEnabled
and set the key value to YES
.
Place the files you want to share in the application's Documents
directory.
Once the device is plugged into the user's computer, ITunes 9.1 displays a file sharing area in the Apps tab of the selected device.
The user can then add files to the directory or move the files to the desktop computer.
If the application supports file sharing, the Documents
application should be able to recognize and respond appropriately when the file is added to the directory. For example, an application can display the contents of a new file on the interface. Do not present a list of directories to the user and ask them what they want to do with the file.
To learn more about UIFileSharingEnabled
keys, see the Information Properties list reference .
Point-to-point services
On iOS 3.0 and later, the Game Kit framework supports point-to-point connections via Bluetooth. You can use a point-to-point connection to initiate a communication session with a neighboring device, or to implement common features of multiple multiplayer games. Although point-to-point connections are primarily used in games, you can also apply them to other types of applications.
For more information on how to use point-to-point connection features in your application, see the Game Kit Programming Guide . If you need an overview of the game kit framework, check out the game kit framework.
Standard system View Controller
Many frameworks in the Cocoa touch layer contain a view controller that represents the standard system interface. We encourage you to use these view controllers in your applications, which allows you to have a consistent user experience for your programs and systems. If you need to perform the following tasks, select a view controller to use from the appropriate framework:
Display or edit contact information -Use the view controller in the Address Book UI framework.
Create or Edit calendar events -Use the view controller of the event Kit UI framework.
Create an email or SMS message -Use the view controller in the message UI framework.
Open or preview the contents of a file -please use the class in the Uikit framework UIDocumentInteractionController
.
pick a photo from the user's photo gallery -Use the classes in the Uikit framework UIImagePickerController
.
capturing video clips -use the classes in the Uikit framework UIImagePickerController
.
To learn how to choose to use a view controller, see the iOS View Controller Programming Guide . For an understanding of the interface shown by a particular view controller, see the appropriate frame reference.
External Device Support
Devices that install iOS 3.2 can connect an external display device through a set of supported cables. When an external device is connected, the application can use its display to display the content. The information on the screen, including the resolution that the screen can support, can be obtained through the interface of the Uikit framework. You can also associate an application window to a screen through the framework.
UIScreen
Class is used to get screen objects for all current screens, including the device home screen. Screen objects contain information about the properties of the screen, including screen features that take into account the size of the screen and the pixel scale.
You can UIScreenMode
get information from a class on a screen with a specific size pixel scale.
You can assign a window (using UIWindow
a Class) to a specific screen. If you need to mirror the content, you need to provide two separate windows and then display the same content in it.
For further information on the support provided by the above classes, see the corresponding class descriptions in the Uikit Framework reference .
Cocoa Touch Layer contains the framework
The following sections describe the frameworks that the cocoa touch layer contains and the services that these frameworks provide.
Address Book UI Framework
The Address Book UI Framework ( AddressBookUI.framework
) is a set of OBJECTIVE-C programming interfaces that can display the standard system interface for creating or editing contacts. The framework simplifies the work required for the application to display contact information, and it also ensures that the application uses the same interface as other applications to ensure cross-platform consistency.
If you need to learn more about the Address Book UI framework and how to use it, check out the iOS Directory Programming Guide and iOS Address Book Framework reference .
Event Kit UI Framework
IOS 4.0 introduces the event Kit UI Framework ( EventKitUI.framework
), which provides a view control key to show the standard system interface for viewing and editing events. The event kit framework (which looks at the "event Kit framework" for further information on the framework) is the basis for building the framework.
To learn more about the event Kit UI framework classes and methods, see the Event Kit UI Framework reference .
Game Kit Framework
IOS 3.0 introduces the Game Kit Framework ( GameKit.framework
). The framework supports point-to-point and in-game voice features that allow you to add point-to-point network functionality to your applications. Point-to-point connections and in-game voice features are common in multi-player games, but you can also consider adding them to non-gaming applications. This framework provides network functionality through a set of simple and powerful classes built on Bonjour that abstract many network details, making it easier for developers without network programming experience to integrate network functionality into applications.
To learn more about the game kit framework, see the Game Kit Programming Guide and the Game Kit Framework Reference .
IAd Framework
IOS 4.0 introduces the IAD framework ( iAd.framework
). You can use this framework to publish banner ads in your app. Ads are put into the standard view, and you can add them to the user interface and present them to the user at the right time. These views collaborate with Apple's announcement services to automatically handle the loading and presentation of ad content and respond to user clicks on ads.
For more information on how to use IAD in your application, see the IAD framework reference .
MAP Kit Framework
IOS 3.0 Imports the map Kit Framework ( MapKit.framework
), which is an interface that can be embedded in the application, which contains a map view that can be scrolled. You can add custom information to the view and embed it in the application view to programmatically set the various properties of the map, including the area displayed by the current map and the user's orientation. You can also highlight certain areas of the map or additional information using custom or standard annotations, such as using stylus markers.
In an iOS 4.0 system, the framework begins to support draggable labels and custom overlays. A draggable callout allows you to reposition a callout programmatically or by user interaction. Overlays can be used to create complex map callouts consisting of multiple points. Map surfaces such as bus routes, election maps, park boundaries, or meteorological information (such as radar data) can be displayed using overlays.
To learn more about the classes in the Map kit framework, see the Map Kit Framework Reference .
Message UI Framework
IOS 3.0 introduces the Message UI Framework ( MessageUI.framework
). You can use the framework to compose an e-mail message and put it in a user's Outbox to queue for delivery. The framework provides a view controller interface that you can present in your application to allow users to compose messages through the interface. The fields of the interface can be generated based on the content of the message to be sent. For example, you can set up recipients, topics, message content, and include attachments in a message. This interface allows the user to edit the message first and then select Accept. After the user accepts the message content, the corresponding message is placed in the user's Outbox and queued for delivery.
In iOS 4.0 and its subsequent systems, the framework provides an SMS composition panel controller. It allows you to create and edit SMS information directly in the application (without leaving the application). As with the e-mail authoring interface, this interface also allows users to edit SMS messages before sending.
For more information about classes in the message UI framework, refer to the Message UI Framework reference .
UIKit Frame
Uikit Frame ( UIKit.framework
) The OBJECTIVE-C programming interface provides a critical foundation for graphics and event-driven iOS applications. All programs in the iOS system need to implement the following core functions through the framework:
Application Management
User interface Management
Graphics and window support
Multi-tasking support
Handle Touch and move events.
Objects that represent standard system views and controls
Text and Web content related operations
Cut, copy, and paste
Using animations to display user interface content
Integration of other applications into the system via URL
Apple push Notification Service support, please see "Apple Push Notification Service"
Accessibility for users with disabilities
Dispatching and sending of local notifications
Create PDF
Use custom input views (which behave like system keyboards)
Create a custom text view that interacts with the system keyboard
In addition to the underlying code that is linked to the application, Uikit also provides support for the following features that are closely connected to the device:
Accelerator data
Built-in camera (device with camera present)
User's picture library
Device Name and model information
Battery status information
Distance sensor information
Remote control information from the bundled handset
For more information on the UIKIT framework, see the UIKit Framework reference .
Other part of the framework:
1. Audio and video
Core Audio, OpenAL, Media Library, AV Foundation
2. Data management
Core Data, SQLite
3. Graphics and animations
Core Animation, OpenGL ES, Quartz 2D
4. Network
Bonjour, WebKit, BSD Sockets
5. User Application
Address book, Core location, MAP kit, Store Kit
Reference: Http://mobile.51cto.com/iphone-266014.htm, http://blog.csdn.net/top123xcode/article/details/6397684
Ui-cocoa Touch Frame