iOS Application Programming Guide free pdf ebook was written by Apple Inc. on March 03, 2011 consist of 114 page(s). The pdf file is provided by developer.apple.com and available on pdfpedia since April 26, 2011.
Tags:
ios is a trademark or registered trademark of. cisco in the u.s. and the ios runtime environment was designed…...
iOS Application Programming Guide
General
2011-02-24
Tagged with:
You're reading the first 10 out of 114 pages of this docs, please download or login to readmore.
Apple Inc.
© 2011 Apple Inc.
All rights reserved.
No part of this publication may be reproduced,
stored in a retrieval system, or transmitted, in
any form or by any means, mechanical,
electronic, photocopying, recording, or
otherwise, without prior written permission of
Apple Inc., with the following exceptions: Any
person is hereby authorized to store
documentation on a single computer for
personal use only and to print copies of
documentation for personal use provided that
the documentation contains Apple’s copyright
notice.
The Apple logo is a trademark of Apple Inc.
No licenses, express or implied, are granted
with respect to any of the technology described
in this document. Apple retains all intellectual
property rights associated with the technology
described in this document. This document is
intended to assist application developers to
develop applications only for Apple-labeled
computers.
Apple Inc.
1 Infinite Loop
Cupertino, CA 95014
408-996-1010
App Store is a service mark of Apple Inc.
Apple, the Apple logo, AirPlay, Bonjour, Cocoa,
Instruments, iPhone, iPod, iPod touch, iTunes,
Keychain, Mac, Mac OS, Macintosh, Objective-C,
Safari, Sand, and Xcode are trademarks of Apple
Inc., registered in the United States and other
countries.
iPad and Retina are trademarks of Apple Inc.
IOS is a trademark or registered trademark of
Cisco in the U.S. and other countries and is used
under license.
Intel and Intel Core are registered trademarks
of Intel Corportation or its subsidiaries in the
United States and other countries.
OpenGL is a registered trademark of Silicon
Graphics, Inc.
Times is a registered trademark of Heidelberger
Druckmaschinen AG, available from Linotype
Library GmbH.
UNIX is a registered trademark of The Open
Group
Even though Apple has reviewed this document,
APPLE MAKES NO WARRANTY OR REPRESENTATION,
EITHER EXPRESS OR IMPLIED, WITH RESPECT TO
THIS DOCUMENT, ITS QUALITY, ACCURACY,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR
PURPOSE. AS A RESULT, THIS DOCUMENT IS
PROVIDED “AS IS,” AND YOU, THE READER, ARE
ASSUMING THE ENTIRE RISK AS TO ITS QUALITY
AND ACCURACY.
IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT,
INDIRECT, SPECIAL, INCIDENTAL, OR
CONSEQUENTIAL DAMAGES RESULTING FROM ANY
DEFECT OR INACCURACY IN THIS DOCUMENT, even
if advised of the possibility of such damages.
THE WARRANTY AND REMEDIES SET FORTH ABOVE
ARE EXCLUSIVE AND IN LIEU OF ALL OTHERS, ORAL
OR WRITTEN, EXPRESS OR IMPLIED. No Apple
dealer, agent, or employee is authorized to make
any modification, extension, or addition to this
warranty.
Some states do not allow the exclusion or limitation
of implied warranties or liability for incidental or
consequential damages, so the above limitation or
exclusion may not apply to you. This warranty gives
you specific legal rights, and you may also have
other rights which vary from state to state.
Contents
Introduction
About iOS Application Design 9
Understanding the iOS Runtime Environment 10
Designing the Core of Your Application 10
Supporting Common Application Behaviors 10
Executing Code in the Background 10
Meeting the App Store and System Requirements 11
Tuning Performance for the Underlying Device 11
See Also 11
Chapter 1
The Application Runtime Environment 13
Fast Launch, Short Use 13
Specialized System Behaviors 13
The Virtual Memory System 13
The Automatic Sleep Timer 14
Multitasking Support 14
Security 14
The Application Sandbox 14
File Protection 15
Keychain Data 16
The File System 16
A Few Important Application Directories 16
A Case-Sensitive File System 18
Sharing Files with the User’s Desktop Computer 18
Backup and Restore 18
What Is Backed Up? 18
Files Saved During Application Updates 19
iOS Simulator 19
Determining the Available Hardware Support 19
Chapter 2
The Core Application Design 23
Fundamental Design Patterns 23
The Core Application Objects 24
The Application Life Cycle 27
The main Function 28
The Application Delegate 29
Understanding an Application’s States and Transitions 29
Multitasking 36
Checklist for Supporting Multitasking 37
Being a Responsible, Multitasking-Aware Application 37
3
2011-02-24 | © 2011 Apple Inc. All Rights Reserved.
CONTENTS
Responding to System Changes While in the Background 39
Opting Out of Background Execution 41
Windows, Views, and View Controllers 41
The Event-Handling System 42
The Graphics and Drawing System 44
The Text System 44
Audio and Video Support 46
Integration with the Hardware and System Applications 46
Chapter 3
Implementing Common Application Behaviors 49
Preserving the State of Your Application’s User Interface 49
Launching in Landscape Mode 50
Adding Support for AirPlay 50
Files and the File System 51
Getting Paths to Standard Application Directories 51
Sharing Files with the User 52
Working with Protected Files 53
Opening Files Whose Type Is Unknown 54
Implementing Support for Custom File Formats 56
Communicating with Other Applications 58
Implementing Custom URL Schemes 59
Registering Custom URL Schemes 59
Handling URL Requests 60
Displaying Application Preferences 62
Turning Off Screen Locking 63
Chapter 4
Executing Code in the Background 65
Determining Whether Multitasking Support Is Available 65
Declaring the Background Tasks You Support 65
Implementing Long-Running Background Tasks 66
Tracking the User’s Location 66
Playing Background Audio 67
Implementing a VoIP Application 68
Completing a Finite-Length Task in the Background 70
Scheduling the Delivery of Local Notifications 71
Chapter 5
Implementing Application Preferences 73
The Settings Application Interface 73
The Settings Bundle 75
The Settings Page File Format 76
Hierarchical Preferences 76
Localized Resources 77
Creating and Modifying the Settings Bundle 78
4
2011-02-24 | © 2011 Apple Inc. All Rights Reserved.
CONTENTS
Adding the Settings Bundle 78
Preparing the Settings Page for Editing 78
Configuring a Settings Page: A Tutorial 79
Creating Additional Settings Page Files 82
Accessing Your Preferences 83
Specifying Default Values for Preferences 83
Debugging Preferences for Simulated Applications 84
Chapter 6
Build-Time Configuration Details 85
The Application Bundle 85
The Information Property List 87
iTunes Requirements 90
Declaring the Required Device Capabilities 90
Application Icons 92
Application Launch Images 94
Providing Launch Images for Different Orientations 95
Providing Device-Specific Launch Images 96
Providing Launch Images for Custom URL Schemes 96
Creating a Universal Application 97
Configuring Your Xcode Project 97
Updating Your Info.plist Settings 98
Updating Your View Controllers and Views 99
Adding Runtime Checks for Newer Symbols 99
Using Runtime Checks to Create Conditional Code Paths 100
Updating Your Resource Files 100
Using a Single Xcode Project to Build Two Applications 101
Internationalizing Your Application 102
Chapter 7
Tuning for Performance and Responsiveness 105
Do Not Block the Main Thread 105
Use Memory Efficiently 105
Observing Low-Memory Warnings 106
Reduce Your Application’s Memory Footprint 106
Allocate Memory Wisely 107
Floating-Point Math Considerations 108
Reduce Power Consumption 108
Tune Your Code 110
Improve File Access Times 110
Tune Your Networking Code 110
Tips for Efficient Networking 111
Using Wi-Fi 111
The Airplane Mode Alert 112
5
2011-02-24 | © 2011 Apple Inc. All Rights Reserved.
CONTENTS
Document Revision History 113
6
2011-02-24 | © 2011 Apple Inc. All Rights Reserved.
Figures, Tables, and Listings
Chapter 1
The Application Runtime Environment 13
Table 1-1
Table 1-2
Directories of an iOS application 16
Identifying available features 20
Chapter 2
The Core Application Design 23
Figure 2-1
Figure 2-2
Figure 2-3
Figure 2-4
Figure 2-5
Figure 2-6
Figure 2-7
Figure 2-8
Table 2-1
Table 2-2
Table 2-3
Table 2-4
Table 2-5
Listing 2-1
Key objects in an iOS application 25
Application life cycle 27
Launching into the active state 31
Moving from the foreground to the background 32
Handling application interruptions 34
Transitioning from the background to the foreground 35
Processing events in the main run loop 43
Several different keyboards and input methods 45
Design patterns used by iOS applications 23
The role of objects in an iOS application 25
Application states 29
Notifications delivered to waking applications 39
System integration technologies 46
The
main
function of an iOS application 28
Chapter 3
Implementing Common Application Behaviors 49
Figure 3-1
Table 3-1
Table 3-2
Listing 3-1
Listing 3-2
Listing 3-3
Defining a custom URL scheme in the
Info.plist
file 60
Commonly used search path constants 51
Keys and values of the
CFBundleURLTypes
property 59
Getting the path to the application’s
Documents
directory 52
Document type information for a custom file format 57
Handling a URL request based on a custom scheme 61
Chapter 4
Executing Code in the Background 65
Table 4-1
Listing 4-1
Listing 4-2
Listing 4-3
Configuring stream interfaces for VoIP usage 69
Checking for background support in earlier versions of iOS 65
Starting a background task at quit time 71
Scheduling an alarm notification 72
Chapter 5
Implementing Application Preferences 73
Figure 5-1
Organizing preferences using child panes 77
7
2011-02-24 | © 2011 Apple Inc. All Rights Reserved.
FIGURES, TABLES, AND LISTINGS
Figure 5-2
Figure 5-3
Table 5-1
Table 5-2
Table 5-3
Listing 5-1
Chapter 6
Formatted contents of the
Root.plist
file 79
A root Settings page 80
Preference control types 74
Contents of the
Settings.bundle
directory 75
Root-level keys of a preferences Settings page file 76
Accessing preference values in an application 83
Build-Time Configuration Details 85
Figure 6-1
Figure 6-2
Figure 6-3
Table 6-1
Table 6-2
Table 6-3
Table 6-4
Table 6-5
The information property list editor 88
The Properties pane of a target’s Info window 89
The Language preference view 103
A typical application bundle 85
Dictionary keys for the
UIRequiredDeviceCapabilities
key 90
Sizes for images in the
CFBundleIconFiles
key 92
Typical launch image dimensions 94
Launch image orientation modifiers 95
Chapter 7
Tuning for Performance and Responsiveness 105
Table 7-1
Table 7-2
Tips for reducing your application’s memory footprint 106
Tips for allocating memory 107
8
2011-02-24 | © 2011 Apple Inc. All Rights Reserved.
INTRODUCTION
About iOS Application Design
This document is the starting point for learning how to create iOS applications. It contains fundamental
information about the iOS environment and how your applications interact with that environment. It also
contains important information about the architecture of iOS applications and tips for designing key parts
of your application.
The contents of this document apply to all iOS applications running on all types of iOS devices, including
iPad, iPhone, and iPod touch.
9
2011-02-24 | © 2011 Apple Inc. All Rights Reserved.
INTRODUCTION
About iOS Application Design
Note:
Development of iOS applications requires an Intel-based Macintosh computer with the iOS SDK installed.
Understanding the iOS Runtime Environment
The iOS runtime environment was designed to support the needs of mobile users and mobile devices. This
environment requires you to design applications differently than you might for a desktop operating system.
By design, iOS places restrictions on applications to more effectively manage resources and the overall security
of the system. These restrictions encompass everything from the way you manage memory and files in your
application to how your application interacts with the device hardware.
Relevant Chapter:
“The Application Runtime Environment”
(page 13)
Designing the Core of Your Application
The UIKit framework provides the core for all iOS applications. This framework provides the infrastructure
for creating and managing your user interface, handling events, supporting multitasking, and managing
most other interactions with the system. Other system frameworks may provide interesting features but
without the UIKit framework, your application would not run. Understanding the key objects of this framework
(and the design patterns it uses) is therefore a critical part of understanding how to design your application.
Relevant Chapter:
“The Core Application Design”
(page 23)
Supporting Common Application Behaviors
There are several common behaviors that any iOS application might want to implement—for example,
launching your application in a landscape orientation, registering a custom URL type, or doing interesting
things with files. Most of these behaviors require modifying your core application slightly to support them.
Relevant Chapters:
“Implementing Common Application Behaviors”
(page 49)
“Implementing Application Preferences”
(page 73)
Executing Code in the Background
Few applications should ever need to execute code while in the background. The basic multitasking support
provides applications with the ability to remain in the background in a suspended state, thereby preserving
battery life. However, applications that provide specific services to the user may ask the system for permission
to run in the background so that they can continue providing those services.
10
Understanding the iOS Runtime Environment
2011-02-24 | © 2011 Apple Inc. All Rights Reserved.
You're reading the first 10 out of 114 pages of this docs, please download or login to readmore.