资料介绍
Contents
Introduction Introduction 13
Who Should Read This Document? 14
Organization of This Document 14
Providing Feedback 15
See Also 15
Chapter 1 iPhone OS Overview 17
iPhone OS Feature Summary 17
Development Tools 19
About iPhone Development 19
Application Styles 20
Application Basics 23
The Multi-Touch Interface 25
Windows and Drawing 26
Key Integration Features 28
Before You Go Any Further 31
Chapter 2 iPhone OS Technologies 33
Cocoa Touch 33
Media 34
Graphics Technologies 34
Core Audio 35
OpenAL 36
Video Technologies 36
Core Services 37
Address Book 37
Core Foundation 37
Core Location 38
CFNetwork 38
Security 38
SQLite 39
XML Support 39
Core OS 39
3
2008-07-08 | 2008 Apple Inc. All Rights Reserved.
Chapter 3 Development Environment 41
The Development Process 41
Creating Your Project and Writing Code 42
Beginnings 43
Using Code Completion 48
Using API Reference Lookup 49
Accessing Documentation 51
Setting Your Application’s Icon 52
Building and Running Your Application 52
Working with the iPhone Simulator 53
Building Your Application for the iPhone Simulator 53
Running Your Application on the Simulator 53
Capabilities of the iPhone Simulator 55
Working with a Device 55
Preparing Devices for Development 55
Building Your Application for a Device 60
Running Your Application on a Device 60
Using the Organizer 60
Backing Up Your Digital Identifications 62
Debugging Your Code and Measuring Performance 63
Debugging with Xcode 63
Tuning Application Performance 65
Conditional Linking to System Frameworks 66
Managing Application Data 67
Chapter 4 Application Design Guidelines 69
The Runtime Environment 69
Fast Launch, Short Use 70
The Virtual Memory System 70
Managing Your Memory Usage 70
Reducing Your Application’s Memory Footprint 71
Allocating Memory Wisely 71
Observing Low-Memory Notifications 72
Performance and Responsiveness 73
Using Memory Efficiently 73
Improving Drawing Performance 73
Reducing Power Consumption 74
Tuning Your Code 74
Security 74
The Application Sandbox 74
Using the Available Security Technologies 75
File and Data Management 76
Application Directory Structure 76
Backup and Restore 77
4
2008-07-08 | 2008 Apple Inc. All Rights Reserved.
C O N T E N T S
Getting Paths to Application Directories 78
Reading and Writing File Data 79
File Access Guidelines 83
Saving State Information 83
Case Sensitivity 84
Networking 84
User Interface Design Considerations 84
Chapter 5 The Application Environment 87
Core Application Architecture 87
The Event and Drawing Cycle 87
The Application Life Cycle 90
Application Interruptions 92
The Application Bundle 93
Application Configuration 95
The Information Property List 95
Custom URL Schemes and Interapplication Communication 98
Application Icon and Launch Images 102
The Settings Bundle 102
Launching in Landscape Mode 102
Internationalizing Applications 105
Chapter 6 Windows and Views 109
What AreWindows and Views? 109
The Role of UIWindow 109
The Role of UIView 110
UIKit View Classes 111
The Role of View Controllers 114
View Architecture and Geometry 114
The View Interaction Model 114
The View Rendering Architecture 117
View Coordinate Systems 119
The Relationship of the Frame, Bounds, and Center 120
Coordinate System Transformations 121
Content Modes and Scaling 122
Autoresizing Behaviors 124
Creating and Managing the View Hierarchy 125
Creating a View Object 127
Adding and Removing Subviews 127
Converting Coordinates in the View Hierarchy 129
Tagging Views 130
Modifying Views at Runtime 131
Animating Views 131
Responding to Layout Changes 133
5
2008-07-08 | 2008 Apple Inc. All Rights Reserved.
C O N T E N T S
Redrawing Your View’s Content 134
Hiding Views 134
Creating a Custom View 134
Initializing Your Custom View 135
Drawing Your View’s Content 135
Responding to Events 136
Cleaning Up After Your View 137
Chapter 7 Event Handling 139
Events and Touches 140
Event Delivery 141
Responder Objects and the Responder Chain 141
Regulating Event Delivery 142
Handling Multi-Touch Events 143
The Event-Handling Methods 143
Handling Single and Multiple Tap Gestures 144
Detecting Swipe Gestures 146
Handling a Complex Multi-Touch Sequence 147
Event-Handling Techniques 148
Chapter 8 Graphics and Drawing 151
Quartz Concepts and Terminology 151
The View Drawing Cycle 152
The Native Coordinate System 152
Graphics Contexts 153
Points Versus Pixels 154
Color and Color Spaces 155
Supported Image Formats 155
Drawing Tips 156
Deciding When to Use Custom Drawing Code 156
Improving Drawing Performance 156
Maintaining Image Quality 157
Drawing with Quartz and UIKit 157
Configuring the Graphics Context 158
Creating and Drawing Images 160
Creating and Drawing Paths 161
Drawing Text 161
Creating Patterns, Gradients, and Shadings 161
Drawing with OpenGL ES 162
Setting Up a Rendering Surface 162
Best Practices 164
Implementation Details 166
For More Information 169
Applying Core Animation Effects 170
6
2008-07-08 | 2008 Apple Inc. All Rights Reserved.
C O N T E N T S
About Layers 170
About Animations 171
Chapter 9 Audio and Video Technologies 173
Using Sound in iPhone OS 173
Audio Sessions 174
Playing Short Sounds Using System Sound Services 174
Playing Sounds with Control Using Audio Queue Services 176
Playing Sounds with Positioning Using OpenAL 179
Recording Audio 179
Parsing Streamed Audio 180
Mixing and Processing Sounds 180
Audio Unit Support in iPhone OS 181
Triggering Vibration 181
Tips for Manipulating Audio 181
Preferred Audio Formats in iPhone OS 182
Playing Video Files 183
Chapter 10 Device Features 185
Accessing Accelerometer Events 185
Choosing an Appropriate Update Interval 186
Isolating the Gravity Component From Acceleration Data 187
Isolating Instantaneous Motion From Acceleration Data 187
Getting the Current Device Orientation 188
Getting the User’s Current Location 188
Taking Pictures with the Camera 190
Picking a Photo from the Photo Library 192
Chapter 11 Application Preferences 193
Guidelines for Preferences 193
The Preferences Interface 194
The Settings Bundle 195
The Settings Page File Format 196
Hierarchical Preferences 197
Localized Resources 198
Adding the Settings Bundle to Your Application 198
Editing Settings Pages 199
Creating Settings Page Files 203
Accessing Your Preferences 204
Debugging Preferences for Simulated Applications 205
7
2008-07-08 | 2008 Apple Inc. All Rights Reserved.
C O N T E N T S
Appendix A Apple Applications URL Schemes 207
Mail Links 207
Phone Links 208
Map Links 209
YouTube Links 210
iTunes Links 210
Document Revision History 211
8
2008-07-08 | 2008 Apple Inc. All Rights Reserved