Appendix A

Testing Your App on a Device

The iOS Simulator is a handy tool for testing your application as you are developing it. However, it is no substitute for testing on an actual device. Certain features, such as the accelerometer and camera, cannot be tested on the simulator at all.

Testing your application on your device is slightly different from giving it to a small number of users for beta testing. When it is your own device, you can physically connect it to your Mac and use Xcode to test/debug your app while it executes on the device. Distributing your app to a few users for beta testing is achieved through TestFlight, a process covered in detail in Appendix B.

Before you can test your app on a device, you need to prepare the device for testing and configure a few options in Xcode. The process itself can seem quite complicated at first. This appendix goes through the various steps required to test your apps on a device with Xcode.

Obtaining and Registering UDIDs

Each iOS device has a unique 40-digit identifier, commonly referred to as the device UDID. Before you can test your app on a device with Xcode, you will need to register the UDID of that device with the iOS Provisioning Portal. You can obtain this UDID through the Xcode Device Manager.

To obtain the UDID for a device, simply connect it to your Mac and access the Devices Manager by selecting Window arrow Devices. Click the device in the list on the left-hand side and note the value of the Identifier field (see Figure A.1).

Screenshot of iOS Devices window with Abhishek's Phone option encircled and an arrow pointing to identifier, encircled.

Figure A.1

To register a device for development, simply click the Use for Development button in the Devices Manager window. You will be asked to provide the Apple ID and password you used to register as an iOS developer. If the device has already been set up for development, then the Use for Development button will not be visible.

You can also register UDIDs manually. To do this, you must log in to your iOS developer account at https://developer.apple.com/ios. Click the Member Center link on the top-right corner of the page to navigate to the member center. Within the member center, click the Certificates, Identifiers & Profiles link (see Figure A.2).

Screenshot of iOS developer account at Apple Inc. with Certificates, Identifiers & Profiles encircled in red.

Figure A.2

Next, click the Devices link in the iOS Apps category on the left-hand side of the page (see Figure A.3).

Screenshot of iOS developer account with Devices link in the iOS Apps category encircled on the left.

Figure A.3

The Devices screen shows you a list of devices registered to your account. You can register up to 100 devices of each type a year (note that deleting a device does not count toward this limit). There are five device types:

To add a device to your account, click the Add button located above the list of devices and fill in the UDID of the device along with a name with which you would like to refer to the device (see Figure A.4). Click Continue to add the UDID to the device list. This list can be reset once a year, when you renew your paid membership.

Screenshot of two screens with plus button encircled on the iOS devices bar in one screen, and an arrow pointing to Name and UDID option encircled under Register Device option, with an arrow pointing to Continue button, encircled.

Figure A.4

Creating an App ID (Bundle Identifier)

The next step involves creating and registering a unique identifier for your app; this is known as the App ID (or Bundle ID). In addition to uniquely identifying your application, an App ID allows your application to receive remote notifications, communicate with external accessories, or share keychain data with other applications in a suite, and use iCloud services.

An App ID consists of an organization identifier and an application identifier (see Figure A.5). When you create a new project in Xcode, you are asked to provide an organization identifier, and the App ID is generated for you by appending the name of the project to the organization identifier. To distribute the application through the App Store, the identifier used to create the Xcode project must be registered with your iOS developer account. You can always change the Bundle Identifier for an existing application by editing the Bundle Identifier key in the project's info.plist file.

Screenshot of TestOnDevice window with the project's info.plist file selected, and a row highlighted with values Bundle Identifier in Key, String in Type, and $(PRODUCT_BUNDLE_IDENTIFIER) in Value.

Figure A.5

To create an appropriate App ID, log in to your iOS developer account at https://developer.apple.com/ios. Click the Member Center link in the top-right corner of the page to navigate to the member center. Within the member center, click the Certificates, Identifiers & Profiles link, and then in the Identifiers section under the iOS Apps category click on the link to App IDs.

To create a new App ID, click the New App ID button on the top-right side (see Figure A.6).

 Screenshot of iOS developer account with a plus symbol encircled next to iOS App IDs on the top-right side.

Figure A.6

Provide a descriptive name for the new App ID in the Name field and select Team ID in the App ID prefix drop-down. Select the Explicit App ID radio button under the App ID suffix section and provide a unique identifier in the Bundle ID field that ends in the name of the Xcode project you are going to create (or have created).

Typically, you create this identifier by combining the reverse-domain name of your website and the name of your Xcode project. For example, if your company identifier is com.acmecorp and your Xcode project is called cloudkitphotos, then the bundle identifier specified should resemble com.acmecorp.cloudkitphotos. Your browser window should resemble Figure A.7.

Screenshot of iOS developer account in Registering an App ID section with Name under App ID specified as A new app id, and the Bundle ID specified is com.acmecorp.cloudkitphotos.

Figure A.7

If you do not mind your apps sharing data between them, you can use an asterisk instead of the application name, thus creating a string of the form com.domainname.*.

Such an App ID is called a wildcard App ID and can be used repeatedly across multiple applications. If you want to create a wildcard App ID, simply select the relevant radio button on the page (see Figure A.8).

Screenshot of App ID Suffix Section in iOS developer account with Wildcard App ID option checked and Bundle ID set to com.domainname.*,.

Figure A.8

The downside of wildcard App IDs is that certain features such as Remote Push Notifications and iCloud support are not available.

Click the Continue button to proceed. You will be presented with a summary of the App ID information. Click on Submit to finish creating the App ID.

Creating a Development Certificate

The next step is to create and install a development certificate. Creating a development certificate involves creating an appropriate certificate request and submitting this request to the iOS Provisioning Portal. Once the certificate is ready, you will be able to download and install it on your Mac.

To create a certificate request, launch the Keychain Access utility from the Applications folder on your Mac. When the Keychain Access utility is running, choose Keychain Access arrow Certificate Assistant arrow Request a Certificate from a Certificate Authority.

In the Certificate Assistant dialog box (see Figure A.9), specify the e-mail address and account name used to access the iOS Developer Program, and ensure the Saved to Disk radio button is selected. Click the Continue button to save the certificate request as a file on your Mac.

Screenshot of Certificate Assistant dialog box with e-mail address and account name specified and Saved to Disk radio button is selected and encircled, with a Continue button at the bottom.

Figure A.9

To create a development certificate from your certificate request file, log in to your iOS developer account at https://developer.apple.com/ios. Click the Member Center link on the top-right corner of the page to navigate to the member center. Within the member center, click the Certificates, Identifiers & Profiles link, and then under the iOS Apps category, look under the Certificates category and click on All.

To create a new development certificate, click the Add button (+) on the top-right side (see Figure A.10).

Screenshot of Certificates, Identifiers & Profiles link under the Certificates category All is grayed, and iOS Certificates listed, with a plus symbol at the top-right.

Figure A.10

You will now be asked to choose the type of certificate you want to create. Select iOS App Development from the list of options (see Figure A.11), scroll down to the bottom of the page, and click Continue.

Screenshot of Add iOS Certificate section with iOS App Development selected from the list of options under What type of certificate you need?

Figure A.11

The next screen contains some general information on what a certificate request file is and how to create one (see Figure A.12). Because you have already created one, scroll to the bottom of the page and click Continue.

Screenshot of Add iOS Certificate section of iOS app developer account with About Creating a Certificate Signing Request (CSR) section, and a Continue button at the bottom.

Figure A.12

In the next screen, use the Choose File button to select the certificate request file that you saved on your Mac and then click the Generate button to create the development certificate (see Figure A.13).

Screenshot of Generate your certificate. section with Choose file button encircled and an arrow pointing to Generate button encircled at the bottom.

Figure A.13

If you are not part of a team, and are solely responsible for handling your iOS Developer account, your certificate is issued automatically and available to download in a few minutes. You may need to refresh your browser window. If you are part of a team, your team manager will need to first approve the certificate request. When your certificate is ready to download, you will see its status listed as Issued, and a Download link will be available.

Download the certificate and save it to your Mac; by default, the certificate should be saved to your Downloads folder.

If you haven't done so already, download the Worldwide Developer Relations Certificate from the Apple PKI authority page (see Figure A.14). This page is located at https://www.apple.com/certificateauthority/.

Screenshot of Apple PKI authority page with Worldwide Developer Relations Certificate link encircled.

Figure A.14

This certificate is also available to download at the bottom of the Create Certificate page, where you select the type of certificate to generate (Figure A.15).

Screenshot of Create Certificate page with Worldwide Developer Relations Certificate link encircled and Continue button at the bottom.

Figure A.15

Creating a Provisioning Profile

After having registered your device UDID, App ID, and creating a development certificate, you will need to create a development provisioning profile. A provisioning profile groups an App ID, a certificate, and device UDIDs into a single entity. The certificate in question would be the development certificate you just generated in the previous section, and the device-specific information would be a list of UDIDs on which you want to debug your application.

To create a development provisioning profile, log in to your iOS developer account at https://developer.apple.com/ios. Click the Member Center link on the top-right corner of the page to navigate to the member center. Within the member center, click the Certificates, Identifiers & Profiles link, and then under the iOS Apps category, find Provisioning Profiles and click All.

Click the New Profile button on the top-right side (see Figure A.16).

Screenshot of iOS Provisioning Profiles bar under the Certificates, Identifiers & Profiles link with plus button encircled.

Figure A.16

You will be asked to choose between a development or a distribution provisioning profile. A distribution provisioning profile is used to submit applications to iTunes Connect. For the moment, select the iOS App Development option and click Continue (see Figure A.17).

Screenshot of Add iOS Provisioning Profiles section in iOS app developer account with iOS app development option checked under Development section and Continue button at the bottom.

Figure A.17

As mentioned earlier in this section, a development provisioning profile connects three pieces of information:

The next step requires you to select an App ID that will be associated with this provisioning profile. Select an App ID from the list of available identifiers (see Figure A.18) and click Continue.

Screenshot of the iOS developer account with the Select App ID. option under Add iOS Provisioning Profile section, and App ID specified as CloudKitPhotos AppID and a Continue button at the bottom.

Figure A.18

Select one or more development certificates that will be included in the profile. You must make sure to sign the app in Xcode using one of the certificates you select here. Select a suitable certificate and click Continue (see Figure A.19).

Screenshot of iOS developer account with Select ceritificates section and Select All option checked with Abhishek Mishra (iOS Development) option checked.

Figure A.19

Next, you must select one or more devices that will be included in this provisioning profile. The corresponding identifiers for these devices must be registered with your development account. Your app will only be testable on these devices (see Figure A.20).

Screenshot of the iOS developer account with the Select devices. option under Add iOS Provisioning Profile section and Select All and all devices selected and a Continue button at the bottom.

Figure A.20

The final step involves providing a suitable name for the profile and clicking the Generate button. When the profile is created, you will be provided an option to download it onto your computer. (see Figure A.21).

Screenshot of the iOS developer account with the Name this profile and generate option and Name filled in as CloudKitPhotos Dev Profile and a Generate button at the bottom.

Figure A.21

If you were to now click the All link under the Provisioning section of the left-hand side menu, you should see an entry for the new profile in the list of available profiles. You can also download a provisioning profile from this list.

Once the profile has been downloaded, simply locate it in the Downloads folder on your Mac and double-click it to install it in Xcode.

Configuring Your Project

The final step in the process involves setting up your Xcode project and preparing an appropriate build. Before you begin, make sure you have installed both your development certificate and development provisioning profile.

Open the project that you want to test on a device. If the project's App ID is different from what has been registered with the iOS Provisioning Portal, edit the value of the Bundle identifier key in the project's info.plist file to match.

Save the info.plist file if you have edited it, and then connect one of the provisioned iOS devices to your Mac and ensure that the Scheme/Target selector in the Xcode toolbar is set to build for an iOS device (see Figure A.22).

Screenshot of Project window with drop down box showing Abhishek's iPhone and all the devices, and Version set to 1.0 and Build set to 1 under Identity tab.

Figure A.22

Access the project's properties by selecting the root project node in the project navigator. Select the build target and then switch to the Build Settings tab.

Scroll down to the Code Signing section and locate the node labeled Provisioning Profile. You may need to expand this node to see the values for individual build configurations (such as debug, release). Select the provisioning profile you created earlier from the list of profiles for the debug configuration (see Figure A.23).

Screenshot of Project window with debug option selected, and debug drop down window with Swift iCloud Test Dev Profile selected from a list of options.

Figure A.23

Now look for a node called Code Signing Identity. Expand this node to reveal a node called Debug, and then expand the Debug node to reveal a node called Any iOS SDK. Ensure the value of this node is set to be the development certificate you created and installed earlier (see Figure A.24).

Screenshot of Project window with Any iOS SDK selected under Debug option in Code Signing Identity and a drop down with the option iPhone developer: Abhishek Mishra (EPE8F6H2MD) selected.

Figure A.24

Your Xcode project is now ready to be tested on an iOS device. Simply click the Run button on the Xcode toolbar to begin.