Testing iOS 5 Apps on the iPhone – Developer Certificates and Provisioning Profiles
Previous | Table of Contents | Next |
Creating a Simple iPhone iOS 5 App | An Overview of the iPhone iOS 5 Application Development Architecture |
Learn SwiftUI and take your iOS Development to the Next Level |
In the chapter entitled Creating a Simple iPhone iOS 5 App we were able to run an application which we had created running in the iOS Simulator environment bundled with the iOS 5 SDK. Whilst this is fine for most cases, in practice there are a number of areas which cannot be comprehensively tested in the simulator. For example, no matter how hard you shake your computer (not something we actually recommend) or where in the world you move it to, neither the accelerometer nor GPS features will provide real world results within the simulator (though the simulator does have the option to perform a basic virtual shake gesture and to simulate location data). If we really want to test an iOS application thoroughly in the real world, therefore, we need to install the app onto a physical iPhone device.
In order to achieve this a number of steps are required. These include generating and installing a developer certificate, creating an App ID and provisioning profile for your application, and registering the devices onto which you wish to directly install your apps for testing purposes. In the remainder of this chapter we will cover these steps in detail.
Note that the provisioning of physical devices requires membership in the iOS Developer Program, a topic covered in some detail in the chapter entitled Joining the Apple iOS Developer Program.
Creating an iOS Development Certificate Signing Request
Any apps that are to be installed on a physical iPhone device must first be signed using an iOS Development Certificate. In order to generate a certificate the first step is to generate a Certificate Signing Request (CSR). Begin this process by opening the Keychain Access tool on your Mac system. This tool is located in the Applications -> Utilities folder. Once launched, the Keychain Access main window will appear as illustrated in Figure 7-1:
Figure 7-1
Within the Keychain Access utility, perform the following steps:
1. Select the Keychain Access -> Preferences menu and select Certificates in the resulting dialog:
Figure 7-2
2. Within the Preferences dialog make sure that the online Certificate Status Protocol (OCPS) and Certificate Revocation List (CRL) settings are both set to Off, then close the dialog.
3. Select the Keychain Access -> Certificate Assistant -> Request a Certificate from a Certificate Authority… menu option and enter your email and name exactly as registered with the iOS Developer Program. Leave the CA Email Address field blank and select the Saved to Disk and Let me specify key pair information options:
Figure 7-3
4. Clicking the Continue button will prompt for a file and location into which the CSR is to be saved. Either accept the default settings, or enter alternative information as desired at which point the Key Pair Information screen will appear as illustrated in Figure 7-4:
Figure 7-4
5. Verify that the 2048 bits key size and RSA algorithm options are selected before clicking on the Continue button. The certificate request will be created in the file previously specified and the Conclusion screen displayed. Click Done to dismiss the Certificate Assistant window.
Submitting the iOS Development Certificate Signing Request
Having created the Certificate Signing Request (CSR) the next step is to submit it for approval. This is performed within the iOS Provisioning Portal that is accessed from the Member Center of the Apple developer web site. Under Developer Program Resources on the main member center home page select iOS Provisioning Portal. Within the portal, select the Certificates link located in the left hand panel to display the Certificates page:
Figure 7-5
Click on the Request a Certificate button, scroll down to the bottom of the text under the heading Create an iOS Development Certificate and click on the Choose File button. In the resulting file selection panel, navigate to the certificate signing request file created in the previous section and click on Choose. Once your file selection is displayed next to the Choose File button, click on the Submit button located in the bottom right hand corner of the web page. At this point you will be returned to the main Certificates page where your certificate will be listed as Pending Issuance.
Click on the link to download the WWDR intermediate certificate and, once downloaded, double click on it to install it into the keychain. This certificate is used by Xcode to verify that your certificates are both valid and issued by Apple.
If you are not the Team Administrator, you will need to wait until that person approves your request. If, on the other hand, you are the administrator for the iOS Developer Program membership you may approve your own certificate request by clicking on the Approve button located in the Action column of the Current Certificates table. If no approval button is present simply refresh the web page and the certificate should automatically appear listed as Issued. Your certificate is now active and the table will have refreshed to include a button to Download the certificate:
Figure 7-6
Installing an iOS Development Certificate
Once a certificate has been requested and issued it must be installed on the development system so that Xcode can access it and use it to sign any applications you develop. The first step in this process is to download the certificate from the iOS Provisioning Portal by clicking on the Download button located on the Certificates page outlined in the previous section. Once the file has downloaded, double click on it to load it into the Keychain Access tool. The certificate will then be listed together with a status (hopefully one that reads This certificate is valid):
Figure 7-7
Your certificate is now installed into your Keychain and you are ready to move on to the next step.
Assigning Devices
Once you have a development certificate installed, the next step is to specify which devices are to be used to test the iOS apps you are developing. This is achieved by entering the Unique Device identifier (UDID) for each device into the Provisioning Portal. Note that Apple restricts developers to 100 provisioned devices per year.
A new device may be added to the list of supported test devices either from within the Xcode Organizer window, or by logging into the iOS Developer Portal and manually adding the device. To add a device to the portal from within Organizer, simply connect the device, open the Organizer window in Xcode using the Organizer toolbar button, select the attached device from the left hand panel and click on the Add to Portal button. The Organizer will prompt for the developer portal login and password before connecting and enabling the device for testing.
Manually adding a device, on the other hand, requires the use of the iPhone’s UDID. This may be obtained either via Xcode or iTunes. Begin by connecting the device to your computer using the docking connector. Once Xcode has launched the Organizer window will appear displaying summary information about the device (or may be opened by selecting the Organizer button in the Xcode toolbar). The UDID is listed next to the Identifier label as illustrated in Figure 7-8:
Figure 7-8
Alternatively, launch iTunes, select the device in the left hand pane and review the Summary information page. One of the fields on this page will be labeled as Serial Number. Click with the mouse on this number and it will change to display the UDID.
Having identified the UDIDs of any devices you plan to use for app testing, select the Devices link located in the left hand panel of the iOS Provisioning Portal, and click on Add Devices in the resulting page. On the Add Devices page enter a descriptive name for the device and the 40 character UDID:
Figure 7-9
In order to add more than one device at a time simply click on the “+” button to create more input fields. Once you have finished adding devices click on the Submit button. The newly added devices will now appear on the main Devices page of the portal.
Creating an App ID
The next step in the process is to create an App ID for each app that you create. This ID allows your app to be uniquely identified within the context of the Apple iOS ecosystem. To create an App ID, select the App IDs link in the provisioning portal and click on the New App ID button to display the Create App ID screen as illustrated in Figure 7-10:
Figure 7-10
Enter a suitably descriptive name into the Description field and then make a Bundle Seed ID selection. If you have not created any previous Seed IDs then leave the default Generate New selection unchanged. If you have created a previous App ID and would like to use this for your new app, click on the menu and select the desired ID from the drop down list. Finally enter the Bundle Identifier. This is typically set to the reversed domain name of your company followed by the name of the app. For example, if you are developing an app called MyApp, and the URL for your company is www.mycompany.com then your Bundle identifier would be entered as:
com.mycompany.MyApp
If you would like to create an App ID that can be used for multiple apps then the wildcard character (*) can be substituted for the app name. For example:
com.mycompany.*
Having entered the required information, click on the Submit button to return to the main App ID page where the new ID will be listed.
Creating an iOS Development Provisioning Profile
The Provisioning Profile is where much of what we have created so far in the chapter is pulled together. The provisioning profile defines which developer certificates are allowed to install an application on a device, which devices can be used and which applications can be installed. Once created, the provisioning profile must be installed on each device on which the designated application is to be installed.
To create a provisioning profile, select the Provisioning link in the Provisioning Portal and click on the New profile button. In the resulting Create Provisioning Profile screen, perform the following tasks:
1. In the Profile Name field enter a suitably descriptive name for the profile you are creating. 2. Set the check box next to each certificate to specify which developers are permitted to use this particular profile. 3. Select an App ID from the menu. 4. Select the devices onto which the app is permitted to be installed. 5. Click on the Submit button.
Initially the profile will be listed as Pending. Refresh the page to see the status change to Active.
Now that the provisioning profile has been created, the next step is to download and install it. To do so, click on the Download button next to your new profile and save it to your local system (note that the file will have a .mobileprovision file name extension). Once saved, either drag and drop the file onto the Xcode icon in the dock or onto the Provisioning Profiles item located under Library in the Xcode Organizer window. Once the provisioning profile is installed, it should appear in the Organizer window (Figure 7-11):
Figure 7-11
Enabling an iPhone Device for Development
With the provisioning profile installed select the target device in the left hand panel of Organizer window and click on the Use for Development button. The Organizer will then prompt you for your Apple developer login and password.
Once a valid login and password have been entered, the Organizer will perform the steps necessary to install the provisioning profile on the device and enable it for application testing.
Associating an App ID with an App
Before we can install our own app directly onto a device, we must first embed the App ID created in the iOS Provisioning Portal and referenced in the provisioning profile into the app itself. To achieve this:
1. In the left hand panel of the main Xcode window, select the project navigator toolbar button and select the top item (the application name) from the resulting list.
2. Select the Info tab from in the center panel:
Figure 7-12
In the Bundle Identifier field enter the App ID you created in the iOS Provisioning Portal. This can either be in the form of your reverse URL and app name (for example com.mycompany.HelloWorld) or you can have the product name substituted for you by entering com.mycompany.${PRODUCT_NAME:rfc1034indentifer} as illustrated in Figure 7-13.
Once the App ID has been configured the next step is to build the application and install it onto the iPhone or iPod Touch device.
iOS and SDK Version Compatibility
Before attempting to install and run an application on a physical iPhone device it is important to be aware of issues relating to version compatibility between the SDK used for the development and the operating system running on the target device. For example, if the application was developed using version 4.3 of the iOS SDK then it is important that the iPhone on which the app is to be installed is running iOS version 4.3 or later. An attempt to run the app on an iPhone with an older version of iOS will result in an error reported by Xcode that reads “Xcode cannot run using the selected device. No Provisioned iOS devices are available. Connect an iOS device or choose an iOS simulator as the destination”.
The absence in this message of any indication that the connected device simply has the wrong version of iOS installed on it may lead the developer to assume that a problem exists either with the connection or with the certification or provisioning profile. If you encounter this error message, therefore, it is worth checking version compatibility before investing what typically turns into many hours of effort trying to resolve non-existent connectivity and provisioning problems.
Installing an App onto a Device
Located in the top left hand corner of the main Xcode window is drop down menu which, when clicked, provides a menu of options to control the target run environment for the current app.
If either the iPhone or iPad simulator option is selected then the app will run within the corresponding simulated environment when it is built. To instruct Xcode to install and run the app on device itself, simply change this menu to the iOS Device setting. Assuming the device is connected, click on the Run button and watch the status updates as Xcode compiles and links the source code. Once the code is built, Xcode will need to sign the application binary using your developer certificate. If prompted with a message that reads “codesign wants to sign using key “<key name>” in your keychain select either Allow or Always Allow (if you do not wish to be prompted during future builds). Once signing is complete the status will change to “Installing <appname>.app on iPhone…”. After a few seconds the app will be installed and will automatically start running on the device where it may be tested in a real world environment.
Learn SwiftUI and take your iOS Development to the Next Level |
Previous | Table of Contents | Next |
Creating a Simple iPhone iOS 5 App | An Overview of the iPhone iOS 5 Application Development Architecture |