application development overview

47
Developing for the App Store

Upload: armin-amiri

Post on 05-Dec-2014

24 views

Category:

Documents


0 download

DESCRIPTION

cghchchhvghjvjv hjghj ghjgh

TRANSCRIPT

Page 1: Application Development Overview

Developing for the AppStore

Page 2: Application Development Overview

Contents

About the Application Development Process 5At a Glance 5

Developing for Apple’s Platforms Is a Mix of Administrative and Coding Tasks 5Apps Published on the App Store Must Be Approved by Apple 5Apps Published on the App Store Must Be Cryptographically Signed 6The Majority of Your Coding Time Is Spent in Xcode 6Administrative Tasks are Performed with Several Resources 6Many Behaviors of an App Are Defined by Data, Not Code 7

How to Use This Document 7

Building an App for the App Store 8Prepare the Development Team 8Configure the Project 8Develop the App 9Publish the App in the App Store 9

Preparing the Development Team 10Enrolling in an Apple Developer Program 10Adding Members to a Team 11

Understanding Membership Privilege Levels 11Organizing the Team in iTunes Connect 13Organizing the Development Team 14Creating Your Team’s Signing Certificates 17

An Example: Signing an iOS App During Development 17Setting Up a Developer for Code Signing 20

To Learn More 21

Creating a Project 22Configuring an Xcode Project for an App 22Creating Provisioning Profiles for Your App 23App Concepts 23

A Bundle ID Uniquely Identifies an App 24App IDs Are Used to Match Apps to Services and Development Teams 25Provisioning Profiles Authorize an App to Launch 26

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

2

Page 3: Application Development Overview

Distributing an App Requires a Distribution Profile 28To Learn More 28

Developing an App 29Designing an App 30

Use the Model-View-Controller Pattern 31Use Data-Driven Designs 32

Writing Code 33Treat Warnings as Errors 33Use the Analyze Action in Xcode to Find Less Obvious Coding Errors 34Implement Unit Tests and User Interface Tests 34

Polishing and Testing an App 35Test on Various Devices 35Use the Archive Action to Create Test Versions of an App 35Use Instruments to Guide Your Efforts 35Ensure That Your App Meets the Approval Guidelines 36

Creating Great Apps 36Design User-Focused Apps 36Develop a Security Model 36Ensure Your App Runs Reliably 37Tune Your App’s Performance 38

To Learn More 38Best Practices in Coding and App Design 39

Publishing an App in the App Store 40Configuring App Data in iTunes Connect 40Submitting the App for Approval 41Shipping an App 41Responding to User Issues 42To Learn More 42

Document Revision History 44

Glossary 45

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

3

Contents

Page 4: Application Development Overview

Figures and Tables

Building an App for the App Store 8Figure 1-1 Development process overview 8

Preparing the Development Team 10Figure 2-1 Steps to create a development team 10Figure 2-2 An individual is the team agent 15Figure 2-3 A small development team 15Figure 2-4 A large development team 16Figure 2-5 Overview of the iOS development provisioning process 18Figure 2-6 The process for approving a device and getting a signing certificate 20Table 2-1 Team roles 12Table 2-2 Privileges assigned to each membership level 12Table 2-3 iTunes Connect roles and responsibilities 13Table 2-4 Abbreviated list of iTunes Connect modules, including availability by role 14

Creating a Project 22Figure 3-1 Starting a new project 22Figure 3-2 Common uses for an app’s bundle ID 24Figure 3-3 Explicit app ID 25Figure 3-4 Wildcard app IDs 26Figure 3-5 Examples of wildcard matching 26Figure 3-6 Overview of the development provisioning process 27

Developing an App 29Figure 4-1 The development process 29Figure 4-2 The development process is an iterative process 29Figure 4-3 Distribution between development tasks varies over time 30Figure 4-4 Model-View-Controller pattern 31

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

4

Page 5: Application Development Overview

There has never been a better time to create apps for iOS and OS X. Apple provides tools that make developmenteasy and straightforward. This document presents a high-level view of the stages in developing an app, fromcreating a team to responding to feedback from users.

Develop Test Distribute

At a GlanceThis document walks you through the process of developing apps for the App Store. By the time you finishreading this document, you should be ready to organize your development team and devise a plan to design,code, and publish an app on the App Store.

Developing for Apple’s Platforms Is a Mix of Administrative and Coding TasksMost of the time spent developing your app is spent on coding tasks, but throughout the development process,there are also a number of administrative tasks you must perform. This mix of tasks can be handled by a singledeveloper, or the work can be divided between different people on a development team.

Most administrative tasks appear at the start and the end of a development project. For example, when youdevelop your first app, one person must sign an agreement with Apple to become an Apple developer. Thisperson, known as the team agent, bears the legal responsibility for the team, adds people to the team anddefines each person’s responsibilities and privileges.

Chapters: “Building an App for the App Store” (page 8)

Apps Published on the App Store Must Be Approved by AppleThe App Store is a curated store and restricts what apps may be sold on the App Store. Apple takes theseprecautions to provide the best experience possible for our users. For example, apps that are sold on the AppStore must not crash or exhibit other major bugs. A major part of the publishing process is to submit your appto Apple for approval.

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

5

About the Application Development Process

Page 6: Application Development Overview

Relevant Chapters: “Publishing an App in the App Store” (page 40)

Apps Published on the App Store Must Be Cryptographically SignedCode signing is used to provide a layer of security to users, your development team, and Apple. Signing anapp makes it resistant to malicious tampering; if an attacker modifies the app, it can no longer be executedbecause the code signing has been broken. Code signing also provides a clear chain of responsibility if maliciouscode is included in a signed app. Although both iOS and OS X require code signing to publish an app on theApp Store, iOS takes this security a step further; no apps can execute on an iOS device, even during development,unless they are signed.

When you organize a development team, the team agent (or a person that task is delegated to) decides whichmembers of your team are permitted to sign your apps and creates the necessary code signing resources forthose developers.

Relevant Chapters: “Preparing the Development Team” (page 10), “Creating a Project” (page 22)

The Majority of Your Coding Time Is Spent in XcodeXcode integrates coding, debugging, and user interface design in a single development environment. You useXcode throughout the development process, even using it when you are ready to submit an app for approval.When you install Xcode, other apps are installed with Xcode that you can use to improve the quality of yourapps. For example, the Instruments application provides many tools to record and analyze data about how anapp acts while running. Using the data, you can formulate plans to ensure that your apps run correctly andefficiently.

Relevant Chapters: “Creating a Project” (page 22), “Developing an App” (page 29)

Administrative Tasks are Performed with Several ResourcesWhen you manage a team, you use various resources to perform tasks. Here are the most frequently usedresources:

● The Member Center website is primarily used by the team agent to invite members to join the developmentteam and to configure their privilege levels.

● The iOS Provisioning Portal (or for OS X development, the Developer Certificate Utility app) is used tocreate the code signing resources for your team. A team admin (either the team agent or a member ofthe team this task has been delegated to) uses these tools to provide the necessary code signing resourcesto members of your team.

About the Application Development ProcessAt a Glance

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

6

Page 7: Application Development Overview

● The iTunes Connect website is used to manage information related to the business side of your appdevelopment, including sales and financial information, information displayed in the App Store for yourapp, and information stored on Apple’s servers for your apps. As with the Member Center, the team agentdecides how much access each person on your team is permitted on iTunes Connect.

Relevant Chapters: “Preparing the Development Team” (page 10), “Creating a Project” (page 22),“Publishing an App in the App Store” (page 40)

Many Behaviors of an App Are Defined by Data, Not CodeIn addition to the code you write, data you provide is used to define how the store displays your app as wellas how your app executes. The data can even affect what the operating system displays about your app whenit isn’t running.

Some data is contained in files stored alongside an executable; this combination of data and files is referredto as an application bundle. Other data is stored on Apple servers—for example, information displayed foryour app on the App Store is primarily stored on iTunes Connect. Regardless of where the data is stored,keepin mind that an app is more than a simple executable; it exists in an ecosystem of code, data, and services.

Relevant Chapters: “Creating a Project” (page 22), “Developing an App” (page 29), “Publishing anApp in the App Store” (page 40)

How to Use This DocumentRegardless of the role you play on a development team, you should read this document to get a betterunderstanding of steps the team must follow to develop an app for the App Store.

If you are a programmer, some concepts described in this document will make more sense to you if you finishone of the following app tutorials before reading this document:

● iOS: Start Developing iOS Apps Today

● OS X: Start Developing Mac Apps Today

About the Application Development ProcessHow to Use This Document

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

7

Page 8: Application Development Overview

Here are the steps to create and ship an app for the App Store. Although these steps are presented in a specific,logical order, occasionally the needs of your app or your development team require you to perform these stepsin a different order or even backtrack to a step you have already performed. For example, any time you addsomeone to your team, you have to go back and perform some administration tasks.

Figure 1-1 shows a high-level overview of the development process; each of these steps is primarily anadministrative step or a coding step. Administrative steps are usually handled by the team agent or someonethe team agent has delegated some authority to. Coding tasks are primarily handled by programmers on theteam.

Figure 1-1 Development process overview

CodingAdministrative

Prepare thedevelopment

team

Administrative

Publishthe app in the

App StoreCreate

a projectDevelopthe app

The remainder of this chapter explains each of these steps. Later chapters go into more detail about the stepsand the kinds of tasks that must be performed to complete them.

Prepare the Development TeamOne person signs up as a team agent and in the process creates a new development team. The team agentcan invite other people to join the team and set their access privileges. Finally, the team sets up code signingcertificates and other resources necessary for developers on the team to sign apps.

Configure the ProjectThe next step is to create a new Xcode project for the app. You choose an Xcode template that most closelycorresponds to the kind of app you want to make and customize the initial settings for the app. You also createother items required to sign and publish your app.

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

8

Building an App for the App Store

Page 9: Application Development Overview

Depending on the design of your app and the services you plan to use in it, you may find yourself performingother kinds of app configuration in this step. Some Apple technologies require a combination of code youwrite and data you configure to operate properly. For example, Apple Push Notification Service requires youto create special certificates used to authenticate your server to the push notification service. If you know upfront that you plan to use push notification in your app, you may also create these push notification certificatesduring this step.

Develop the AppThis step is what most people think of when they talk about developing an app: Designing user interfaces andfunctionality, implementing those ideas in code, and testing the resulting app to ensure it works correctly.While a lot of this work is programming, this step also includes other important tasks, such as creating dataassets used by the app. These assets, including but not limited to icons, sound files, and artwork, are useddirectly by the app or by the operating system on the app’s behalf. Many assets need to be localized into otherlanguages or locales; an important part of designing your app is planning for the assets you need to createand knowing which assets should be localized.

You continue to polish and refine your app until it is ready to ship.

Publish the App in the App StorePublishing an app on the App Store requires a few administrative tasks. Your team provides the informationdisplayed for the app by the App Store. You also submit the app to Apple for approval. Once the app is approved,you set the date the app should appear for sale in the App Store. Then, you use Apple’s tools to monitor thesales of the app, customer reviews, and crash reports. These data can help you prepare bug fixes and help youdecide on what improvements to make in a major revision to the app. When you have bug fix or a majorrevision ready to ship, you send it for approval and set a publication date, just as you did for the initial release.

Building an App for the App StoreDevelop the App

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

9

Page 10: Application Development Overview

Most people think of a development team as a group of programmers, designers, and artists who work togetherto develop an app. That explanation is also true when you develop for iOS or OS X, but it isn’t complete. Adevelopment team takes on the additional meaning of a group created and managed on the Apple Developerwebsite. Some additional tasks during the development process are performed using this development teamyou’ve created. If you create a team with yourself as the only member, you take on all of these tasks. If you arepart of a larger team, the work and the responsibilities may be divided between the group.

Each person on the development team has a unique Apple ID, an account used by the developer programsto authenticate that person. Further, access privileges can be configured separately for each person. Thisflexibility allows your team to restrict critical tasks, such as publishing the app on the App Store, to a smallsubset of its participants.

This chapter starts by describing the various roles that members of a team may fill. It then provides guidanceabout how you may want to go about organizing the team. Finally, it describes work the team must do toallow people of the team to sign apps. Figure 2-1 shows all of the required steps.

Figure 2-1 Steps to create a development team

Administrative

Enroll in anApple developer

program

Create the team’s signing

certificatesAdd members

to the teamOrganize

the team in iTunes Connect

Enrolling in an Apple Developer ProgramTo start, one person must enroll in either the iOS or OS X developer program; this person becomes the teamagent for the team. The team agent may enroll in both programs if your team intends to develop apps forboth operating systems. During this step, the team agent signs the legal agreements required to become anApple developer and prepares the financial paperwork so that the team can be paid for purchases from theApp Store.

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

10

Preparing the Development Team

Page 11: Application Development Overview

The team agent is special; he or she has unrestricted access to the team and is legally responsible for the team.The team agent also performs most of the tasks to organize the team. If desired, after others have joined theteam, the team agent can delegate some of this authority to other members of the team, allowing those othersto perform these tasks instead.

Important: Because the team agent is the person with legal responsibility for the team, the team may notdemote the team agent using the tools on the website, nor can the team agent’s privileges be restricted.To change the person acting as the team agent, you must contact Apple directly.

The team agent might need to sign updated or new licensing agreements, particularly when the team wantsto incorporate specific technologies into an app. For example, an app that uses the iAd service requires yourteam agent to sign a separate agreement.

Adding Members to a TeamAfter the team agent has joined a developer program, he or she adds other people to the team and sets theirprivileges. If you are the team agent and the sole developer on your team, no additional configuration isneeded, because the team agent always has access to all account features. However, you should continue toread this section to understand the kinds of tasks you may need to perform throughout the rest of thedevelopment process.

To add a new person to the team, the team agent sends an invitation to the person; part of sending an invitationincludes setting that person’s privileges on the team. When he or she accepts the invitation, that person isautomatically added to the team.

Understanding Membership Privilege LevelsA person’s membership level on the team defines the level of access he or she has to the Apple developerwebpages and the team information stored there. This privilege level extends to the kinds of tasks that developeris allowed to perform on behalf of the team. For example, only certain members of the team are allowed topublish apps on the App Store. By giving you control over these task privileges, Apple makes it easier for youto maintain good security practices for the team.

If the team has joined multiple developer programs, when you configure a person’s privileges, you set a separateprivilege level for each program. You can also choose to not give someone access to a program.

Table 2-1 lists the roles a team participant can play and provides a basic description of each. Each level ofaccess includes all the capabilities of the levels below it.

Preparing the Development TeamAdding Members to a Team

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

11

Page 12: Application Development Overview

Table 2-1 Team roles

DescriptionRole

A team agent is legally responsible for the team and acts as the primary contact withApple. The team agent can change the access level of any other member of the team.

Team agent

A team admin can set the privilege levels of other participants, although a teamadmin cannot demote the team agent. Team admins manage all assets used to signyour apps, either during development or when your team is ready to distribute anapp. Team admins are the only people on a team that can sign apps for distributionon nondevelopment devices. Team admins also approve signing certificate requestsmade by team members.

Team admin

A team member gains access to prerelease content delivered by Apple on thatprogram’s portal. A team member can also sign apps during development, and butonly after he or she makes a request for a development signing certificate and hasthat request approved by a team admin.

Teammember

Table 2-2 drills deeper into this list of privileges granted to members of your team. Although this documenthasn’t explained all these privileges, most will be clear to you by the time you finish reading it.

Table 2-2 Privileges assigned to each membership level

Teammember

Team adminTeam agentPrivilege

Legal responsibility for the team

Primary contact with Apple

Invite team admins and team members

Approve a request for a development signingcertificate

Add devices for development and user testing

Create app IDs

Request a distribution signing certificate from Apple

Create development and distribution provisioningprofiles

Preparing the Development TeamAdding Members to a Team

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

12

Page 13: Application Development Overview

Teammember

Team adminTeam agentPrivilege

Enable app IDs to use Apple Push Notification orIn-App Purchase

Create SSL certificates for the Apple Push NotificationService

Request a development signing certificate

Download development provisioning profiles

View prerelease website content

Organizing the Team in iTunes ConnectThe privileges set in the previous section primarily pertain to the development process: They define who isallowed to sign apps, who is allowed to create signing certificates, and so on. However, the team agent alsomanages access privileges to the iTunes Connect website. For example, changing the price of an app is a taskyou likely want to limit to a small number of people on your team. Access to the iTunes Connect website isconfigured separately and is designed to be more fine-grained than the access you set in Member Center. OniTunes Connect, each person on the team can be assigned one or more roles; each role has different privileges.Table 2-3 describes the roles at a high level.

Table 2-3 iTunes Connect roles and responsibilities

ResponsibilitiesRole

The legal role is automatically assigned to the team agent, and only the team agent ispermitted to have this access. The legal role allows the team agent to sign legal contractsand other agreements.

Legal

The admin role grants access to all tasks in iTunes Connect except for those assigned tothe legal role. A team agent is always assigned the admin role, and this access cannot berevoked without changing which person on the team acts as the team agent. An admincan assign iTunes Connect roles to other people on the team.

Admin

The finance role grants access to financial reports and sales information. The finance rolealso authorizes the person to view contract, tax, and banking information.

Finance

The sales role grants access only to sales data.Sales

Preparing the Development TeamOrganizing the Team in iTunes Connect

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

13

Page 14: Application Development Overview

ResponsibilitiesRole

The technical role grants the ability to edit the app information stored in iTunes Connectand to create test accounts needed to test In-App Purchase support in an app.

Technical

Table 2-4 lists the most common modules you need to access in iTunes Connect, along with the roles that areallowed to access each module. The legal role is not shown, because only the team agent has those rights. Allparticipants have the ability to edit their own personal details stored in their accounts in iTunes Connect.

Table 2-4 Abbreviated list of iTunes Connect modules, including availability by role

TechnicalSalesFinanceAdminResponsibility

Manage Users

Manage Your Applications

Manage Test Users

Sales and Trends

Contracts, Tax, and Banking

Payments and Financial Reports

Organizing the Development TeamNow that you understand the roles people can assume in Member Center and iTunes Connect, you shouldconsider how you want to organize the team. Organizing the team requires more than setting privilegesdescribed above. The size of the team affects how you organize it and its assets.

Preparing the Development TeamOrganizing the Development Team

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

14

Page 15: Application Development Overview

The smallest team is a single person—you. You act as the team agent and have full privileges to perform anytask. The disadvantage of a one-person team is that you have to do all the work. You need to set up the assetsneeded to sign and publish an app, configure all the information in iTunes Connect, develop an app, andmarket it.

Figure 2-2 An individual is the team agent

Agent

Admin

Members

A more common configuration is a small developer team. On a small team, the team agent is also a programmer,but defers some of the administration overhead to another person on the team. The team agent handles allof the financial and sales operations for the team, while the team admin ensures that the developers on theteam have what they need to get the job done.

Figure 2-3 A small development team

Source code server

Agent

Admin

Members

Preparing the Development TeamOrganizing the Development Team

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

15

Page 16: Application Development Overview

If your team is large, you can divide the tasks further. Some people on the team might not be programmers,including the team admin. The sales and financial roles might be filled by people with a business background.You might even have in-house testers who are not also programmers. The task of creating and shipping appscould be delegated to one or more dedicated team admins. You might even partition the work further anddivide the team between iOS and OS X development.

Figure 2-4 A large development team

Build bot

Source code server

Agent

Admins

Finance

Sales

Testers

Members

As the team grows, the need for coordination between the different people on the team increases. In particular,the cost of development errors increases when you have more programmers on the team. For example, if youare the sole member of the team, you can store all your work on a single computer and do all of the workthere. Xcode even allows you to create a local source code repository to store your code. But what happenswhen the team grows in size?

When the team grows to a moderate size, you need more infrastructure. You want a separate computer to actas a remote source code repository; members of the team pull down the code from the remote repository totheir computers, make changes, and send those changes back to the server. But when multiple developers aresyncing code, the chance of an error being checked into the code increases. To minimize problems, you usuallywant multiple branches of development, including stable branches that hold the code you use to build your

Preparing the Development TeamOrganizing the Development Team

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

16

Page 17: Application Development Overview

shipping app and experimental or developmental branches used for new development. These strategies requirea deeper understanding of the underlying source code repository and require you to define specific policiesthat describe how code gets integrated between the different branches you maintain.

If your team grows very large, checking erroneous code into developmental branches could impair your team’sproductivity. By the time you discover an error, it might already have been synced to other people’s computers.After you correct the error, propagating the fixes to everyone on the team still takes time. The frequency ofsuch incidents and the time lost for each incident increase as the size of the team increases; these losses, whenaggregated, cripple your team’s effectiveness. To avoid this lost productivity, you should add additionalinfrastructure for code management. For example, you might adopt a process of continuous integration bycreating a dedicated build machine (known as a build bot) that automatically checks out each change andrebuilds your app. By building new changes as they arrive, you discover errors earlier; you might even configurethe server to back out such changes before others on the team pull down the offending code. If your projectincludes unit tests or automated user tests, the build computer can also run those tests to verify that yoursource code still passes the tests. This process, known as smoke testing , increases the team’s confidence thatcode stored in the development branches builds and works properly.

As the team grows larger, you want to automate tasks that are repeatable, predictable, and costly to performby hand. By automating common tasks, you reduce the burden on the team and allow it to focus on designingand implementing code.

Creating Your Team’s Signing CertificatesApps distributed on the App Store must be cryptographically signed. You may also need to sign the app duringdevelopment.

● On OS X, an app must be signed during development if it uses iCloud or application sandboxing.

● On iOS, all apps must be signed during development.

Regardless of which platform you are developing for, everyone on the team should understand the codesigning process. This section describes the assets that are needed to sign an app and authorize it to run on adevice, and then explains how people on the team acquire the assets they need to sign apps. Some of theseassets should be created now as you organize your team; the rest are created each time you start a new project.

An Example: Signing an iOS App During DevelopmentFigure 2-5 shows everything that is needed to build and sign an iOS app during development. Signing appsduring OS X development or signing to distribute an app on either platform follows similar procedures. Fornow, focus on this example. While you are developing an iOS app, it can only be installed on iOS devices

Preparing the Development TeamCreating Your Team’s Signing Certificates

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

17

Page 18: Application Development Overview

specifically marked for development. To run an app on such a development device, you install a signed versionof the app and a development provisioning profile that authorizes the signed app to be launched. Withouta profile that authorizes it to launch, iOS prevents the app from launching.

Figure 2-5 Overview of the iOS development provisioning process

Build and sign

Signed application

Team adminTeam member

List of authorized signing certificates

App ID

List of authorized device IDs

Development Provisioning Profile

List ofcertificates

List ofdevice IDsApp ID

Intermediate signing certificates

Xcode project

Development signing certificatePublic key

Private key

Development device

Creating development provisioning profiles is described in detail in “Creating a Project” (page 22); for now,understand that a development provisioning profile is a signed file whose contents define the scope of theprofile:

● The development profile authorizes a specific set of apps to run.

● The development profile authorizes a specific list of devices to run those apps.

● The development profile authorizes a specific list of development certificates to sign those apps.

Preparing the Development TeamCreating Your Team’s Signing Certificates

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

18

Page 19: Application Development Overview

In addition to being installed on the development device, the profile must be installed on your developmentcomputer also. The profile authorizes the copy of Xcode to sign the app. Xcode only signs an app and installsit on the device if the profile authorizes the signing certificate and the app being signed. Logically, this makessense; if a profile that authorizes the app to launch is not available, such an signed app would serve no purpose.

Next, take a close look at the left side of Figure 2-5. To sign code during development, you need the followingitems installed in the keychain on your development system:

● A private key.

● A development signing certificate (authorized by a team admin). This signing certificate includes thepublic key associated with the private key.

● An intermediate signing certificate (provided by Apple). This certificate acts as an intermediary betweenyour development signing certificate and the signing authority.

The combination of a signing certificate and the corresponding private key is called a code signing identity.When you build an iOS app, Xcode compiles it, signs it using your code signing identify, and installs it on thedevice. If a provisioning profile compatible with the signed app is also installed on the device, you can launchand debug the app.

Preparing the Development TeamCreating Your Team’s Signing Certificates

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

19

Page 20: Application Development Overview

Setting Up a Developer for Code SigningFigure 2-6 shows the process for setting up a new developer on the team. The full details of this process arespelled out in documents listed later in this chapter; see “To Learn More” (page 21). For now, you only needto understand this process at a high level. Team members make requests; team admins authorize or deny theserequests. There are two separate pieces that need to be authorized: adding a development device to the team’sdevices and creating the code signing identity used to sign apps during development.

Figure 2-6 The process for approving a device and getting a signing certificate

Team member Team admin

Adds the device IDto the list of devices

Sends a request for a signing certificate

Installs both the signingcertificate and the

intermediate certificate

Sends the device IDto a team admin

Creates a public key / private key

pair

Approves the signingcertificate request

Time

To add a device to the team, you send the unique device ID (UDID) for the device to a team admin; this processhappens outside of any tools provided by Apple. For example, you might send an email to the team adminwith the device’s device ID. The team admin adds the device to the team’s devices. Typically, the team adminalso adds this device to any development provisioning profiles associated with the team, although that is notstrictly required. For example, if your team wants to limit an app to specific devices, then you might chooseto add the device only to a subset of the team’s profiles.

To get a signing certificate, a team member uses Xcode to request a signing certificate. Xcode automaticallycreates a new public and private key and requests that a new development signing certificate be created forthe team member. After a team admin receives and approves the certificate request, the team member canuse Xcode to automatically install the required pieces into the keychain.

Although setup is described here as a single process, you do not need to perform both steps for every memberof your team. For example, you might want internal testers to be associated with the development team onthe Apple Developer website but not allow those testers to build and sign your app. In this case, the team

Preparing the Development TeamCreating Your Team’s Signing Certificates

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

20

Page 21: Application Development Overview

admin might include a tester’s device in the team’s devices but not allow the tester to create a code signingidentity. Similarly, an external tester’s device must be included in the team’s device list in order for it to beauthorized to run an app.

While the above discussion was about development signing certificates, when you organize your team, theteam should also request a distribution signing certificate. A distribution signing certificate is required if youintend to distribute apps to nondevelopment devices. Unlike development signing certificates, where eachteam member has a separate code signing identity, a team has a only one code signing identity used to signapps for distribution. The procedure for creating a distribution certificate is similar to the workflow describedabove, but the request for a distribution signing certificate is made by a team admin using a new public/privatekey pair and Apple approves the request. After the certificate is approved by Apple, only a team admin candownload the resulting certificate.

Important: All developers on the team should keep a secure backup of their private key. If the key is lost,that team member can no longer sign code without creating a new identity. Worse, if the key is stolen,another person may be able to impersonate that developer. Protecting the private key associated with theteam’s distribution signing certificate is absolutely critical ; in the wrong hands, someone might be able toimpersonate your team, and upload malicious software for app approval. Private keys are stored only inthe keychain and thus cannot be retrieved if lost.

If a developer on your team needs to set up another development computer, in order to sign code, he orshe must also copy the private key over to the new computer.

To Learn MoreIf you are on an iOS team, read the following documents to learn more about creating a team and setting upits signing certificates:

● If you are a team admin, read iOS Team Admin Guide .

● If you are a team member, read Tools Workflow Guide for iOS .

● Read iTunes Connect Development Guide for a comprehensive description of iTunes Connect and thetasks you perform there.

If you are on an OS X team, read the following documents to learn more about creating a team and setting upits signing certificates:

● Regardless of whether you are a team member or a team admin, read Tools Workflow Guide for Mac .

● Read iTunes Connect Development Guide for a comprehensive look at iTunes Connect and the tasks youperform there.

Preparing the Development TeamTo Learn More

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

21

Page 22: Application Development Overview

When you are building apps to learn more about app development or to experiment with a concept, you mightnot follow the formal process listed here. When your app is destined for the App Store, you should do morework up front. Figure 3-1 shows the steps you should perform when starting work on a new app. This chapterexplains the steps you should follow to organize your project and other related items you need in order todistribute your app. It then explains many of the important concepts related to those steps.

Figure 3-1 Starting a new project

Coding

Configure anXcode project

for the app

Administrative

Createprovisioning

profiles

Configuring an Xcode Project for an AppWhen you create a new Xcode project, you are presented with settings to configure the new project; you canfind more information about these settings in Tools Workflow Guide for iOS and Tools Workflow Guide for Mac .You should carefully consider the template you use to create an app and the settings used to configure theproject; starting with the right template helps speed the development process. For example, if you wereplanning to write an iOS game using the OpenGL ES graphics framework, the OpenGL ES Application templateis an ideal starting point, because it provides a lot of initialization code required by all OpenGL ES apps.

One of the settings you provide when you create a new project is the bundle ID for your app. When you setthe bundle ID, it is automatically inserted into your project’s information property list file.

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

22

Creating a Project

Page 23: Application Development Overview

Note: When you create a new project, Xcode gives you the option to automatically create a localsource code repository. You almost always want to select this option, even for test projects. Usingsource code control is essential to good development practices. It ensures that you have a workinghistory of the work you’ve completed on your app, allowing you to make changes to your codeknowing you can revert changes that did not work out as intended. You can even use Xcode to easilycompare the working copy of your source code with the code stored in your source code repository.

Creating Provisioning Profiles for Your AppIf you intend to ship your app on the App Store, a team admin should perform these steps after your projectis created:

1. Create an explicit app ID whose bundle ID search string exactly matches the new app’s bundle ID.

2. Use the new app ID to create a development provisioning profile.

3. Use the new app ID to create one or more distribution provisioning profiles.

Although an explicit app ID is not strictly required for all projects, having one, and the related provisioningprofiles, gives you finer control over who can build and run each app you create. An explicit app ID is alsonecessary for many Apple services; creating it early means you are always ready to implement those servicesin the app.

Similarly, a distribution provisioning profile isn’t necessary until you are ready to distribute your app, butcreating those profiles at the start of the project makes it easier for you to verify that your signing andprovisioning is set up correctly. Creating an ad hoc distribution profile at the start of your project also allowsyou to build a release version of the app at any time and send it to external testers using nondevelopmentdevices.

App ConceptsWhen you create a project, you use a bundle ID to identify a specific app, and an app ID to match that bundleID. The app ID is used as part of a provisioning profile that authorizes an app to launch. The next few sectionsdescribe these three concepts in detail.

Creating a ProjectCreating Provisioning Profiles for Your App

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

23

Page 24: Application Development Overview

A Bundle ID Uniquely Identifies an AppA bundle ID is a string used to precisely identify a single app. Bundle IDs are not used just during thedevelopment process; when your app is installed on a device, it is also used by the operating system. Forexample, the preferences system uses this string to identify the app for which a given preference applies. Incontrast, Launch Services uses the bundle ID to locate an app capable of opening a particular file, using thefirst app it finds with the given identifier. And, in iOS, the bundle ID is used in validating the app’s signature.

The bundle ID string must be a uniform type identifier (UTI) that contains only alphanumeric (A-Z,a-z,0-9),hyphen (-), and period (.) characters. The string should be in reverse-DNS format. For example, if your company’sdomain is Ajax.com and you create an app named Hello, you could assign the string com.Ajax.Hello asyour app’s bundle ID.

During the development process, you use an app’s bundle ID in many different places to identify the app.Figure 3-2 shows the most common places where an app’s bundle ID is used during the development process.

Figure 3-2 Common uses for an app’s bundle ID

Bundle ID

Xcode project

iTunes Connect

iCloudcontainer ID

App ID

● The bundle ID itself is stored in the information property list file (Info.plist) inside your project. Thisfile is later copied into your app’s bundle when you build the project.

● When you are ready to publish an app, you use the bundle ID to identify the app in iTunes Connect. TheApp Store submission process correlates the bundle ID from the app you submit with the data you providein iTunes Connect. See “Configuring App Data in iTunes Connect” (page 40).

● When developing your app, you need a development provisioning profile with an app ID that is compatiblewith the app’s bundle ID.

● When you implement iCloud support in your app, the container IDs you specify are based on the bundleIDs of one or more apps.

Creating a ProjectApp Concepts

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

24

Page 25: Application Development Overview

App IDs Are Used to Match Apps to Services and Development TeamsApp IDs are strings and share some characteristics with bundle IDs. But app IDs differ in two important ways.First, app IDs are not required to identify a specific app—an app ID can instead identify a collection of apps.Second, an app ID contains additional information that allows it to be associated with a specific developmentteam. Although the convention for bundle IDs starts each with a company identifier in reverse DNS format,that convention is not strictly enforced, and it cannot be used to identify your development team. App IDs areprimarily used when creating development and distribution provisioning profiles, both described later in thischapter.

An app ID is a string containing two parts, a team ID and a bundle ID search string, with a period (.) separatingthe two parts. Each part of an app ID has different and important uses for your app.

The team ID is a unique 10-character string generated by Apple. The team ID is what associates an app ID witha specific team. Apps that share the same team ID can also share keychain data, such as user names andpasswords.

Two kinds of app IDs are supported:wildcard app IDs and explicit app IDs . The bundle ID search string determinesthe type of an app ID.

Explicit App IDs Match a Single AppAn explicit app ID uses a search string that exactly matches the bundle ID of an app you are building. Becausethe exact bundle ID is specified, the app ID matches only that app.

Figure 3-3 Explicit app ID

A1B2C3D4E5•com•domainname•applicationname

Team ID(generated by Apple)

Bundle ID search string(determined by Developer)

Important: In order to incorporate Apple Push Notification Service (APNS), In-App Purchase, or GameCenter features into your app, you must create an explicit app ID for your app.

Wildcard App IDs Match Multiple AppsA wildcard app ID allows you to use an app ID to match multiple apps; wildcard app IDs are useful when youfirst start developing new apps because you don’t need to create a separate app ID for each app. However,wildcard app IDs can’t be used to provision an app that uses APNS, In-App Purchase, or Game Center.

Creating a ProjectApp Concepts

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

25

Page 26: Application Development Overview

A wildcard app ID omits some or all of the bundle ID in the search string and replaces that portion with anasterisk character (*). The asterisk must always appear as the last character in the search string.

Figure 3-4 Wildcard app IDs

A1B2C3D4E5• *

Bundle ID search string(determined by Developer)

Bundle ID search string(determined by Developer)

or, A1B2C3D4E5•com•domainname• *

Team ID(generated by Apple)

Team ID(generated by Apple)

When you use a wildcard app ID, characters preceding the asterisk (if any) must match the characters in thebundle ID, exactly as they would for an explicit app ID. The asterisk matches all remaining characters in thebundle ID. Further, the asterisk must match at least one character in the bundle ID. Figure 3-5 shows an examplesearch string and shows that it matches some bundle IDs but not others.

Figure 3-5 Examples of wildcard matching

com•domain• *com•domain•textcom•domain•iconcom•otherdomain•databasecom•domaincom•domain•

(bundle id search string)

* matches text.

* matches icon.

The d in the pattern fails to find a match.

The • in the pattern fails to find a match.

The * in the pattern fails to match a character.

If an app ID uses an asterisk (*) as the bundle ID, then the search string matches any bundle ID.

Provisioning Profiles Authorize an App to LaunchIn the chapter “Setting Up a Developer for Code Signing” (page 20), you learned how signing certificates arecreated and used to sign app. Now, you need to learn about the other half of the process, the provisioningprofiles used to authorize signing and execution of an app.

There are two kinds of provisioning profiles:

● A development profile, used during development, can be used to authorize apps only on devices configuredfor development.

● A distribution profile is used to distribute apps. There are multiple kinds of distribution profiles, eachassociated with a specific method of distribution.

Creating a ProjectApp Concepts

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

26

Page 27: Application Development Overview

Figure 3-6 shows the development provisioning process for iOS development again.

Figure 3-6 Overview of the development provisioning process

Build and sign

Signed application

Team adminTeam member

List of authorized signing certificates

App ID

List of authorized device IDs

Development Provisioning Profile

List ofcertificates

List ofdevice IDsApp ID

Intermediate signing certificates

Xcode project

Development signing certificatePublic key

Private key

Development device

When you add devices and signing certificates to a development team, Xcode automatically creates a profilenamed iOS Team Provisioning Profile . This profile is automatically updated when new signing certificates ordevices are added to the team. This profile has three major characteristics:

● It includes all code signing certificates associated with the team.

● It includes all devices associated with the team.

● The app ID in the profile uses an asterisk as the bundle ID.

In other words, the iOS Team Provisioning Profile allows any app to be signed by any team member with asigning certificate and installed on any team device. Because the iOS Team Provisioning Profile is automaticallyupdated, this profile is very helpful when programmers on your team want to install sample code or simple

Creating a ProjectApp Concepts

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

27

Page 28: Application Development Overview

test apps on development devices. However, when you are developing an app for the App Store, you maywant to create a development provisioning profile instead. When you create your own profile, you can limitany of the three areas to provide additional security:

● You can use an app ID that allows a subset of the team’s apps to be launched; with an explicit app ID, youcan limit the profile to a single app.

● You can restrict the developers allowed to sign app authorized by the profile.

● You can restrict the devices that apps authorized by the profile may be installed onto.

Distributing an App Requires a Distribution ProfileWhen you are ready to distribute an iOS or Mac app, you not only need the distribution signing certificatecreated when you organized your team, you also need a distribution profile that authorizes the app to run. Ifyou are developing an iOS app, signing the app and distributing it with the appropriate profile is the only wayto install the app on a device not specially configured for development.

The exact contents of a distribution profile differ from the contents of a development profile, and each kindof distribution profile may have slightly different contents. A common requirement limits code signing to theteam’s distribution signing certificate. That said, a distribution profile for distributing an app on the App Storedoesn’t restrict the app to a limited set of devices.

To Learn MoreIf you are on an iOS team, to learn more about the different kinds of distribution profiles and to learn how toconfigure a new project, read the following documents:

● If you are a team admin, read iOS Team Administration Guide .

● If you are a team member, read Tools Workflow Guide for iOS .

If you are on an OS X team, learn more about the different kinds of distribution profiles how to configure anew project by reading Tools Workflow Guide for Mac .

Creating a ProjectTo Learn More

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

28

Page 29: Application Development Overview

Figure 4-1 shows a typical organization of the development process. You design what you want your app todo and how it should work, implement those ideas in code, and then test the code you’ve written.

Figure 4-1 The development process

Polish and testthe app

Designthe app

Coding

Write codefor the app

The figure above gives you an idea of the process, but it doesn’t express the reality of it. In practice, it looksmore like the process shown in Figure 4-1.

Figure 4-2 The development process is an iterative process

Designthe app

Write codefor the app

Polish andtest the app

It is up to you to decide how much time you plan to put into each phase as you iterate through the developmentof your app. For example, you might choose to implement a small number of features on each pass, as is typicalin Agile development, or you might choose to write a design specification that describes how everythingshould work in your app and implement it all at once, or you might choose something in between. Regardlessof which approach you use, polishing your app and iterating over elements of your design is essential todelivering a good experience to the user. You want to make sure your app provides an interface that users caneasily understand; that task is difficult to accomplish without putting your app in front of users and observinghow they interact with it.

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

29

Developing an App

Page 30: Application Development Overview

As you iterate through the development process, notice how your time is divided among the three phasesvaries. For example, at the beginning of the project, you have an idea, but no code to write or test, so more ofyour time is spent on design decisions. As you get ready to ship your app, your designs are mostly complete,you are changing the code only where necessary to fix problems, and you are spending the majority of yourtime testing to verify that your app works correctly and that users love it.

Figure 4-3 Distribution between development tasks varies over time

Design Code Test Design Code Test Design Code Test

Time spent in project

When you first start working on an app, start by reading the specific guides for the operating system you intendto target. These guides describe the technologies available to you, explain the architecture of apps on thatoperating system, and guide you on how your app should look and act to match the expectations of users.The rest of this chapter gives you a high-level overview of key development concepts to consider during eachof the three steps in the iterative process.

Designing an AppWhen you start a new app, keep your design flexible. This suggestion is particularly true for a first app, whenyou are still learning the details of what makes a good app. Alternatively, assume your first project is notsomething you intend to ship but is used instead to learn more about the technologies you need to understand.By designing a flexible architecture, you are better prepared to respond to user feedback during your testingprocess—and even after you ship, too. The following sections describe a couple of techniques that may helpyou with your initial design.

Developing an AppDesigning an App

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

30

Page 31: Application Development Overview

Use the Model-View-Controller PatternThe Model-View-Controller pattern is one of many patterns in common use in Cocoa and Cocoa Touch, and it isessential to designing apps on iOS and OS X. When you use the Model-View-Controller pattern, you divide theconcerns of your app into three major areas; these areas are typically represented in your app by differentclasses.

● Model: What kind of data does your app store? How does it store it? Where is the data stored?

● View: What does your user interface look like? How is it composed? How does it animate?

● Controller: What tasks can a user perform? What things happen as the user interacts with your app’s userinterface? What tasks are necessary for your models and views to interact with each other?

By separating these concerns, you can revise one portion of your app without requiring significant changesin the rest of the app. This concept is important if you intend to redesign your user interface; ideally, you shouldbe able to replace the user interface of your app without changing the model code. Being able to replace theuser interface not only makes it easy to adjust the design of your user interface based on user feedback, it alsomakes it easy to extend your app to provide new user interfaces or share model classes between multiple apps.Figure 4-4 shows a single common data model applied across iOS and Mac apps.

Figure 4-4 Model-View-Controller pattern

Model

Controller

View

Controller

View

Controller

View

Controller

View

Developing an AppDesigning an App

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

31

Page 32: Application Development Overview

In the figure, the iOS app supports both the iPad user-interface idiom and the iPhone user-interface idiom andthe Mac app supports both a windowed and full-screen interface. Using a common set of classes to representyour data model is ideal for an app suite designed to support iCloud; the apps store data in iCloud using asingle file format, but each app uses a separate set of presentation objects. Thus, each app can be tailored topresent an ideal interface for that kind of device.

Use Data-Driven DesignsDo not hard code all of the behavior into your app’s source code. Instead, divide the work of your app betweencode and data. At runtime, the actual behavior of your app should be determined by the data. This pattern isused repeatedly through Cocoa and Cocoa touch. Here are a few examples:

● Localization: Localization often includes storing localized text into strings files; these files are then loadedat runtime. This design allows the language of the user interface to be easily changed; when the app isrelaunched after changing a localization setting, it automatically appears in the new language. Implementinga new interface in a different language may even be possible without changing the source code of yourapp.

● Nib file: A special file type, known as a nib file , stores objects as data. The data inside each nib file definesa custom collection of Objective-C objects, including the class and internal state of each object; this stateincludes references to other objects, connecting all of the objects into an object graph . When you developan app, you create nib files and store them in your project; when you build the app, Xcode copies the filesinto the app bundle. When your app is running and needs new copies of the objects stored in the nib file,it instantiates the nib file. The operating system extracts the data stored in the nib file, re-creates theobjects, and connects the resulting object graph to other objects in your app, just as if you had createdand configured those objects programmatically.

Nib files are used most often to store user interface objects and related objects such as controllers. Xcodeallows you to create or modify nib files using graphical tools. Because the user interface elements arestored as data, you can often create or modify parts of your user interface without changing your app’ssource code. Although a programmer often defines the initial design of a nib file’s contents to connectthe nib file to the underlying app code, separating the nib file as data makes it easier for nonprogrammerswith specialized interface design skills to polish your app’s user interface. Nib files can even be used tolocalize your app by loading different nib files at runtime based on the user’s preferred language or locale.

● Storyboards: In iOS 5, storyboards replace nib files as the preferred way to design an user interface inCocoa Touch apps. Storyboards share many of the same benefits of nib files—they can be created usingcustom tools and stored in the project; the resulting storyboards are copied into the built app and loadedby the app at runtime. A storyboard differs from a nib file by allowing a single storyboard to hold multiplescreens of content as well as transitions between those screens that are triggered when the app is running.The entire collection of screens and transitions is created and modified as a single entity, allowing you tobetter visualize how the user interface is organized. Xcode performs the necessary work to allow portions

Developing an AppDesigning an App

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

32

Page 33: Application Development Overview

of the storyboard file to be instantiated efficiently, just as if you had created your design in multiple nibfiles. The details of how a storyboard does these things are not critical here; the important concept tounderstand is that storyboards are created and loaded as data.

Adopting data-driven programming techniques in your own class designs can pay dividends in other areas aswell. For example, a game might use data files to define the characteristics of elements in the gameplay. Cocoaand Cocoa Touch provide archiving classes that can store this data in a human-readable format, allowing yourdesigners to open these files and tweak the design of the game without recompiling the code. And, althoughstoring this data in files in your app bundle is the easiest way to implement this kind of design, you can evenmove these data files to a network server and allow your app to reload this data live. During development, theability to reload game data without quitting your app can speed this iterative process even more.

So, whether you load your files once at launch or allow the files to be reloaded, being able to change yourapp’s behavior without recompiling code allows you work faster polishing your app’s user interface andbehavior.

Writing CodeWhen coding your app, start by reading the relevant programming guide for the technology you plan to use,if one is available. These guides often provide specific guidance on how classes in a particular framework areintended to be used together. Although you can try to learn how a framework works by reading the headerfiles or the references, programming guides are designed to guide you through the design of the frameworkand how to structure your app to use that technology.

Objective-C is a flexible language. That flexibility, and its underlying C architecture, make it easy to write appsthat crash or run incorrectly. Ideally, you never want erroneous code to live in your project for very long, andyou definitely don’t want erroneous code to be checked into your source code repository. To avoid that,consider the practices described in the following sections.

Treat Warnings as ErrorsOften, warnings indicate code that may not work properly at runtime. Even when a warning does not indicatea fatal error, its presence in your project may obscure more critical warnings that do represent errors. Beaggressive; set up your Xcode project to treat warnings as errors, and fix those errors just as you would anyother compiler error.

Developing an AppWriting Code

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

33

Page 34: Application Development Overview

Use the Analyze Action in Xcode to Find Less Obvious Coding ErrorsThe Objective-C compiler has a built-in code analyzer that detects many common coding errors. It not onlyunderstands C programming errors, but it also has been programmed to enforce many Cocoa and Cocoa Touchcoding conventions. Thus, if your app has subtle logic errors or is failing to conform to the coding conventions,it can provide an early indicator of a problem and explain exactly where your logic went awry. Always checkyour code with the Analyze command before committing it to the repository.

Implement Unit Tests and User Interface TestsUnit tests are additional code you write to test your app. Because you understand the logic of how your classesare intended to be used, you can write targeted tests to verify that this behavior works correctly. A typical unittest instantiates objects from your app’s classes, configures them, and then calls one or more methods on anobject to perform actual work. Finally, the unit test executes one or more test assertions to verify that theresults match what the test expected. Xcode has built-in support for unit testing; when you create your project,you can automatically have Xcode include a target that builds and runs unit tests. All you need to do is fill inthe tests.

By consistently and regularly using unit tests, you decrease the chance of a breaking change being introducedinto your source code for any length of time. When you find a bug that your unit tests didn’t detect, that bugis often an indication of another unit test you need to write. In addition to helping you verify that your classeswork correctly, unit tests often improve the design of your classes. To test an object in isolation, the objectmust be able to be instantiated without having large numbers of dependencies on other objects or classes.You may even need to be able to override some of the behaviors of the instantiated test object so that it callsyour test code, rather than calling some other subsystem of your app. This flexibility, when incorporated directlyinto your class design, forces the classes under test to have clean interfaces.

User interface classes are sometimes harder to test using unit tests; for those areas, you may want to use anautomation tool to script the user interface itself. If you are an iOS developer, you can use interface automationprovided by the Instruments app; see Instruments User Guide .

Depending on how you intend to use unit tests, you may write tests at different stages in your developmentprocess. For example, a common Agile practice, test-driven development, suggests that you never add newcode to your app without first creating a failing test. Creating a failing test first helps ensure that the test iscorrect before writing the code. When using TDD, your test suite grows organically alongside your app and isrefactored as you change your class interfaces and implementations. Other practices are possible as well. Forexample, if you are experimenting widely on the design and implementation of your app, you might not beready to lock down the interface of a class until after a few iterations. In that situation, you may choose todesign the tests after your class designs have stabilized somewhat. Implementing tests later may force you tomake small changes to the class interface and implementation if you choose this strategy.

Developing an AppWriting Code

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

34

Page 35: Application Development Overview

Polishing and Testing an AppAfter you implement your code, you need to test it to shake out bugs and other incorrect behaviors. And nomatter how many unit tests you write or tools you use up front, you are going to run into bugs. But even morethan that, there are other defects you want to look for. You want to ensure that users are comfortable withyour app’s behavior. You want users to feel confident that your app is well written and is protecting their bestinterests.

The following suggestions have guidelines for polishing your app.

Test on Various DevicesDifferent kinds of devices have different capabilities; testing on more than one kind of device ensures that youare not making assumptions about how your app is going to operate. This step is particularly important whendeveloping apps for iOS; Simulator is useful when developing your app, it has none of the performancecharacteristics or memory restrictions of the actual hardware. You need to put your app on actual devices andtest it there.

Use the Archive Action to Create Test Versions of an AppThe Xcode archive action allows you to build your app and store it, along with critical debugging information,in a bundle that is managed by Xcode. Archives are also used whenever you want to distribute your app, butthey are also useful during development. For example, if you ship a test version of your app to testers, archivingthe debugging information makes it easier to interpret crash reports that they send to you. When you areready to make an archive, take this time to review the other build and compiler settings in your project.

Important: Save the archive for any version of an app you distribute to users. You need the debugginginformation stored in the archive to decipher crash reports.

Use Instruments to Guide Your EffortsThe Instruments app, installed with Xcode, can be easily accessed through the Profile action in Xcode.Instruments is essential for learning how your app uses memory, how it uses the different subsystems of theoperating system, and how well it performs under load. For an iOS app, Instruments can help you study howfast your app depletes a device’s battery.

Developing an AppPolishing and Testing an App

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

35

Page 36: Application Development Overview

Ensure That Your App Meets the Approval GuidelinesIf you’ve already archived an app and you are getting close to publishing it, you should use the Xcode Testaction to verify the app. It tests a number of common problems that can immediately disqualify an app frombeing approved. In addition to using this automated test, you should also read over the guidelines and verifythat your app follows them.

Creating Great AppsCreating great apps is more art than science, but there is still plenty of science you can apply to improve thequality of your apps. In particular, by avoiding potential pitfalls, you avoid making an app that users don’t like.Happy users often give apps a high rating on the App Store and recommend those apps to their friends.

Here are a few areas you should consider at all points during the design and implementation of your app.

Design User-Focused AppsWhen you design your app, focus on providing a great user experience. Avoid unnecessary interruptions orbehaviors that prevent a user from performing tasks in your app.

Focus on the idiom for the device your app is running on and tailor your app’s interface to the user’s expectationson those devices. For example, although an iPhone has less screen space to display its user interface than otherdevices, another, more compelling, difference is the way a user interacts with an iPhone. A user may pull aniPhone out of a pocket to perform a short task, and then immediately put it back—a very short interactionwith the device. In contrast, an iPad not only has more screen space to display the user interface, but also userstend to use an iPad for longer tasks. A Mac has even more screen space and is likely to be used for longer still.When you design an iPhone app, you need to consider that a user’s interaction with your app is going to bebrief, and thus interruptions may be perceived as more bothersome than they might be in an iPad or Mac app.By tailoring the experience to the OS and device and following Apple’s human interface guidelines, your appsshould match up well with a user’s expectations.

Develop a Security ModelSecurity is essential to all apps and operating systems, particularly now. Devices are always networked, all thetime. A compromised device may attempt to attack other devices. And security concerns go beyond attacksto take control of a device; users may store valuable personal data on their devices using your app. If a deviceis lost or stolen, users want to know that their data is safe.

● Focus on the data: Examine how your app receives, stores, transfers and uses data. For example, if yourapp stores data in a file on an iOS device, that data is subject to inspection or modification when the deviceis backed up to iTunes. That data can then be synchronized back to the device and read back into your

Developing an AppCreating Great Apps

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

36

Page 37: Application Development Overview

app. Or, if your app receives data over a network, the data you receive from another entity might be acrafted into a malicious attack. Understanding how data flows through your app (and at what levels oftrust) is critical to anticipating how your app may be attacked. Anticipating how your app might be attackedhelps you design your app to detect and avoid these attacks.

● Acquire only the minimum privileges to perform a task: A compromised app can do anything your appis permitted to do. On OS X, if your app performs tasks that require high levels of privileges, considersplitting your app into multiple processes and giving the secure privileges to a process that performs onlythose tasks.

Another example of this principle is app sandboxing; sandboxing prevents other apps from accessing datafiles stored by your app. iOS apps are automatically sandboxed. On OS X, you need to explicitly implementsandboxing to protect your app.

● Fail securely: If a task performed by your app might fail, always fail in a way that maintains the securityof the device your app is running on and the user’s data.

Ensure Your App Runs ReliablyMake your apps as defect-free as possible. In the real world, errors happen all the time; your app must bedesigned and implemented so that it handles errors returned to it by the operating system. Here’s a smallsubset of common errors your app must expect to happen at any time:

● Network outages: Mobile devices often switch between networks or may be disconnected if the usermoves away from a network hub or cellular tower. If your app requires networking, it must be preparedto be disconnected and reconnected at any time, even in the middle of a network operation.

● Running out of storage: Devices have a finite amount of storage; iCloud also places limits on the maximumamount of data your app can store in the cloud. Your app might exceed the storage limits when it attemptsto write data to a file.

● Running out of memory: Devices also provide a finite amount of memory to your app. On iOS, if yourapp runs out of memory and is unable to free up memory when the system asks for it, it is terminated bythe operating system. On OS X, you app may continue to run if it uses too much memory, but it runs slowerand slower as it uses more virtual memory. Expect your app to run low on memory; it must be preparedto free up caches and other resources.

When considering the design of an app, always try to fail safely . Your app may be terminated because of aprogramming error on your part or an unavoidable condition (such as requesting memory when none isavailable and none can be freed by your app). It may even be terminated directly by the user. You want tomake sure that the user’s data is not corrupted when your app is terminated. For example, one way to failsafely is to do all of the work necessary for a task without changing any of the existing data. Only after the task

Developing an AppCreating Great Apps

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

37

Page 38: Application Development Overview

succeeds do you swap the completed work with the previous contents. This technique is often used whenwriting files to storage; write a new file, and then swap the data for that file with the data for the existing savedfile.

Tune Your App’s PerformanceAn app’s perceived performance is a critical part of its interaction with the user. An app that hangs on thelaunch screen or responds erratically to user input is perceived badly by users. More importantly, poorlyperforming apps are usually inefficient ; on mobile devices, inefficient apps consume more battery power andreduce the usable time of the device on a single battery charge.

As you develop your app, consider these basic practices:

● Understand which features must respond quickly to user requests: For example, an app’s launch timeis almost always something you should improve during the development process. Other critical tasksshould always be performed quickly. When a task cannot be performed quickly, your app’s user interfaceshould provide some clue to the user that the task may take additional time. Tasks that cannot be performedquickly should not block the user interface; perform these tasks in the background instead.

● Fit your app’s implementation to the problems it solves: The choice of classes you use (or algorithmsyou implement) should be based on the needs of your app. For example, there’s a vast difference betweenan app that performs tasks on a dozen items and an app that performs tasks on millions of items. Matchyour design to the workload.

● Avoid premature optimizations: Avoid implementing highly complex algorithms or solutions until youare certain they are necessary for your app’s actual performance. Instead, your early efforts should be tokeep the design readable and understandable. Hide implementation details behind a clean class interfaceso that the implementation can be easily changed without requiring code dependent on that class tochange as well. Ideally, so long as your unit tests continue to pass, you should always be able to changethe implementation of a class to something more efficient without changing any other code in your app.

● Profile your implementation to discover where it spends its time: Often, the code that runs the slowestis not the code you expect to. The most reliable way to understand how an app executes is to profile it.Instruments provides many great profiling tools that you can use to understand the actual behavior ofyour app.

To Learn MoreIf you are an iOS developer, read the following documents:

● Read iOS App Programming Guide to learn more about app programming on iOS.

● Read iOS Technology Overview to learn about the technologies that iOS makes available to an app.

Developing an AppTo Learn More

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

38

Page 39: Application Development Overview

● Read iOS Human Interface Guidelines to learn about how to make your app consistent with iOS’s userinterface conventions.

● Read Tools Workflow Guide for iOS for details about the tasks you must complete to develop your app.

If you are an OS X developer, read the following documents:

● Read Mac App Programming Guide to learn more about app programming on OS X.

● Read Mac Technology Overview to learn about the technologies that OS X makes available to an app.

● Read OS X Human Interface Guidelines to learn about how to make your app consistent with OS X’s userinterface conventions.

● Read Tools Workflow Guide for Mac for details about the tasks you must complete to develop your app.

Best Practices in Coding and App DesignUse these documents to help you improve the quality of your code:

● Read Coding Guidelines for Cocoa to learn about the coding conventions used throughout Cocoa andCocoa Touch. Using these same conventions in your own source code improves the consistency of yourcode.

● Read Secure Coding Guide and Security Overview to learn how to make your app more secure.

● Read Performance Overview to learn how to make your app more efficient.

Developing an AppTo Learn More

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

39

Page 40: Application Development Overview

After the last bug is fixed, the app is ready to ship. Now you need to get it on the App Store.

Configurethe data in

iTunes Connect

Administrative and Coding

Respond tocustomer

issues

Administrative

Submit the app forapproval

Ship it!

Configuring App Data in iTunes ConnectWhen an app is sold in the App Store, the store displays a lot of information about the app, including its name,a description, an icon, screenshots and contact information for your company. To provide that information,you log into iTunes Connect, create a record for your app, and fill in these items. The record in iTunes Connectincludes a field for a bundle ID; the value you place in this field must exactly match the bundle ID for your app.

Some Apple technologies, including Game Center and In-App Purchase, require that an iTunes Connect recordbe created earlier in the development process. For example, with In-App Purchase, you need to create the apprecord so that you can add the details of the items you want to sell. This content needs to be created beforethe development process is complete so that you can use it to test the code you added to implement In-AppPurchase.

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

40

Publishing an App in the App Store

Page 41: Application Development Overview

Important: Although you might need to create the iTunes Connect record before development is complete,you should delay this step as long as possible. Try to implement features that require an iTunes Connectrecord at the end of your development cycle. You must publish your app within a certain amount of timeafter you create an iTunes Connect record; if you exceed this time limit, the record is deleted from iTunesConnect, forcing you to create a new app record and reenter the data. The record is deleted to preventunscrupulous developers from “squatting” on app names for long periods of time. The details are spelledout in iTunes Connect Development Guide.

Alternatively, you might ship a version of your app without these features (thus avoiding the time limit)and implement these features in a later revision to your app.

Submitting the App for ApprovalNear the end of your development time on your app, you started creating archives of your app. To recap, anarchive includes a built version of your app and all of the associated debugging symbol information. Whenyour team is ready to submit an app for approval, a team admin is going to perform two tasks on an archiveyou’ve created.

● Your team admin uses Xcode to validate the archive. Validating an archive performs an automated checkagainst the app in the archive as well as the information you provided in your iTunes Connect record.

● Your team admin uses Xcode to submit the archive for app approval. Xcode transmits the archive to Apple,where it is examined to determine whether it conforms to the app guidelines. For example, apps thatcrash or do not perform the tasks described in your iTunes Connect record are rejected.

If your app is rejected, correct the problems that were brought up during app approval and resubmit it.

Shipping an AppUse iTunes Connect to set a date when your app will be released to the App Store. For example, you can choosea date that immediately releases the app to the App Store after it is approved, or you can set a date sometimein the future. Using a later release date allows you to arrange other marketing activities around the launch ofyour app.

Publishing an App in the App StoreSubmitting the App for Approval

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

41

Page 42: Application Development Overview

Responding to User IssuesYour work isn’t quite done yet. You want to pay attention to how users perceive your app. Customer ratingsand reviews on the App Store can have a big effect on the success of your app; if users run into problems, workquickly to determine the bug and submit a new version of your app through the approval process.

The iTunes Connect site provides data to help you determine how successful your app is, including sales andfinancial reports, customer reviews, and crash logs submitted to Apple by users. Crash logs are particularlyimportant, because they represent significant problems users are seeing in your app. Your team should makeinvestigating these reports a high priority. Here are the kinds of crash logs you might see:

● Application crash: An application crash is generated when execution is halted due to bad memory access,an exception, or some other programming error.

● Low memory: A low memory warning is generated when the app was killed by the system because therewas not enough memory to satisfy the app’s demands.

● User force-quit: A force-quit message is generated because your app became unresponsive and was quitby a user.

● Watchdog timeout: A watchdog timeout is generated when an app takes too long to launch, terminate,or respond to system events.

Except for low memory crash logs, all crash logs contain stack traces for each thread at the time of termination.To view a crash log, you need to open it in the Xcode Organizer. As long as your development computer hasthe archive corresponding to the version of the app that generated the crash log, Xcode automatically resolvesany addresses in the crash log with the actual classes and functions in your app; this process is known assymbolication . This process is described in more detail in the workflow guides.

To Learn MoreWhile designing and implementing your app, and definitely before submitting it to the app approval process,you should read the App Store Review Guidelines.

If you are on an iOS team, these documents are your next steps to learn more about distributing your app:

● If you are a team admin, read iOS Team Administration Guide .

● If you are a team member, read Tools Workflow Guide for iOS .

● Read iTunes Connect Development Guide for a comprehensive look at iTunes Connect and the tasks youperform there.

Publishing an App in the App StoreResponding to User Issues

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

42

Page 43: Application Development Overview

If you are on an OS X team, these documents are your next steps to learn more about creating a team andsetting up its signing certificates:

● If you are a team member or a team admin, read Tools Workflow Guide for Mac .

● Read iTunes Connect Development Guide for a comprehensive look at iTunes Connect and the tasks youperform there.

Publishing an App in the App StoreTo Learn More

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

43

Page 44: Application Development Overview

This table describes the changes to Developing for the App Store .

NotesDate

Updated artwork to show that the app ID prefix is always the team ID.2012-07-17

This document was previously named App Development Overview. It nowhas a new title, new artwork, and many small clarifications and corrections.

2012-01-09

New document that describes the steps for developing iOS and Mac appsand submitting them to the App Store.

2011-10-12

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

44

Document Revision History

Page 45: Application Development Overview

The glossary defines terms used in this document:

app ID A unique digital fingerprint that grants yourapp access to a portion of the keychain; also, onepart of a Development or Distribution ProvisioningProfile.

bundle A bundle is a directory with a standardizedhierarchical structure that holds executable codeand the resources used by that code.

bundle ID A string that uniquely identifies a bundle.

code signing certificate An electronic documentthat associates a digital identity with otherinformation, including a name, email address, orbusiness.

code signing identity The combination of a codesigning certificate and its corresponding private key.A code signing identity is used to sign apps.

Development Provisioning Profile A set of entitiesand entitlements allowing apps to be installed andtested on an development device. A DevelopmentProvisioning Profile consists of a name, a list ofdevelopment certificates, a list of device IDs, and anapp ID.

development team A development team is a eithera single person enrolled in the Individual Programor a team agent and group of team admins and teammembers in the Standard Program.

distribution provisioning profile A set of entitiesand entitlements allowing apps to be distributed. Adistribution provisioning profile consists of a name,a distribution certificate, and an app ID.

development signing certificate A code signingcertificate restricted to app development.

distribution signing certificate A code signingcertificate restricted to app distribution.

iTunes Connect A suite of web-based tools createdfor developers to submit and manage their apps forsale via the App Store.

iOS iOS comprises the operating system andtechnologies that you use to run apps natively oniPhone, iPad, and iPod touch devices. Although itshares a common heritage and many underlyingtechnologies with OS X, iOS was designed to meetthe needs of a mobile environment, where user’sneeds are slightly different.

keychain A database used in OS X and iOS to storeencrypted passwords, private keys, and other secrets.It is also used to store certificates and othernon-secret information that is used in cryptographyand authentication.

source code repository A directory tree or databasethat contains the files managed by a source controlsystem

source control A set of tools and procedures formanaging files and changes made to them over time.Also known as source control management (SCM)or version control.

team agent The original person accepted into adeveloper program for all membership types. Theteam agent has access to all functionality in theDeveloper Program Portal and is responsible foraccepting all developer program agreements.

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

45

Glossary

Page 46: Application Development Overview

team admin A person on a development teamdesignated by the team agent or another teamadmin who has all of the same privileges as teamagents except for signing legal agreements.

team member A person on a development teamwho can request development certificates and installapps on a development device.

test-driven development (TDD) A programmingpractice that advocates writing a failing test casebefore changing the code in a project. Whenpracticing test-driven development, you write a testcase and ensure that it fails, then modify your codeto make the new test (as well as previously writtentests) pass.

unique device ID (UDID) A 40-character string usedto identify a specific iOS device.

unit test A piece of code that exercises some partof your app. A unit test provides a specific input andexpects your code to return a specific output.

Xcode Apple's development environment for OS Xand iOS; it includes all the tools needed to create,debug, and optimize OS X and iOS apps.

Xcode project A group of source files, libraries,media, and other resources needed to build yourproduct.

Glossary

2012-07-17 | © 2012 Apple Inc. All Rights Reserved.

46

Page 47: Application Development Overview

Apple Inc.© 2012 Apple Inc.All rights reserved.

No part of this publication may be reproduced,stored in a retrieval system, or transmitted, in anyform or by any means, mechanical, electronic,photocopying, recording, or otherwise, withoutprior written permission of Apple Inc., with thefollowing exceptions: Any person is herebyauthorized to store documentation on a singlecomputer for personal use only and to printcopies of documentation for personal useprovided that the documentation containsApple’s copyright notice.

No licenses, express or implied, are granted withrespect to any of the technology described in thisdocument. Apple retains all intellectual propertyrights associated with the technology describedin this document. This document is intended toassist application developers to developapplications only for Apple-labeled computers.

Apple Inc.1 Infinite LoopCupertino, CA 95014408-996-1010

Apple, the Apple logo, Cocoa, Cocoa Touch,Instruments, iPad, iPhone, iPod, iPod touch,iTunes, Logic, Mac, Objective-C, OS X, and Xcodeare trademarks of Apple Inc., registered in theU.S. and other countries.

iAd and iCloud are service marks of Apple Inc.,registered in the U.S. and other countries.

App Store is a service mark of Apple Inc.

OpenGL is a registered trademark of SiliconGraphics, Inc.

iOS is a trademark or registered trademark ofCisco in the U.S. and other countries and is usedunder license.

Even though Apple has reviewed this document,APPLE MAKES NO WARRANTY OR REPRESENTATION,EITHER EXPRESS OR IMPLIED, WITH RESPECT TO THISDOCUMENT, ITS QUALITY, ACCURACY,MERCHANTABILITY, OR FITNESS FOR A PARTICULARPURPOSE. AS A RESULT, THIS DOCUMENT IS PROVIDED“AS IS,” AND YOU, THE READER, ARE ASSUMING THEENTIRE RISK AS TO ITS QUALITY AND ACCURACY.

IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT,INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIALDAMAGES RESULTING FROM ANY DEFECT ORINACCURACY IN THIS DOCUMENT, even if advised ofthe possibility of such damages.

THE WARRANTY AND REMEDIES SET FORTH ABOVEARE EXCLUSIVE AND IN LIEU OF ALL OTHERS, ORALOR WRITTEN, EXPRESS OR IMPLIED. No Apple dealer,agent, or employee is authorized to make anymodification, extension, or addition to this warranty.

Some states do not allow the exclusion or limitationof implied warranties or liability for incidental orconsequential damages, so the above limitation orexclusion may not apply to you. This warranty givesyou specific legal rights, and you may also have otherrights which vary from state to state.