Running the application on an iOS device
To run the application on an iOS device, you must perform the following steps:
- Join the Apple iOS Developer Program.
- Create a Provisioning Profile within the iOS Provisioning Portal.
- Verify that the Code Signing section's Code Signing Identity within the project settings is set to our provisioning profile name.
Let's assume that we already have a subscription to the iOS Developer Program. Now, you need to create an iOS Development Certificate and Provisioning Profile.
Go to https://developer.apple.com, then go to the "Member Center" link, and enter your Apple ID and password. After that, go to Developer Program Resources and select Certificates, Identifiers & Profiles. The following screen will appear:
Generating the iOS developer certificate
Under the Certificates section, press the + button in order to start certificate generation. On the screen, select iOS App Development.
Then, press the Continue button. After that, we see the instructions for how to generate Certificate Signing Request (CSR) on our computer. At this stage, we can begin to generate the CSR on our computer. In the Applications
folder on your Mac, open the Utilities
folder and launch Keychain Access. Within the Keychain Access drop-down menu, go to Keychain Access | Certificate Assistant | Request a Certificate from a Certificate Authority. After that, we will see the following screen:
In the User Email Address field, I entered my current e-mail. Usually, this is the same e-mail to access the Apple Developer Portal. In the Common Name field, I usually enter my name. If you have a company, it might be the company name. I am the owner of an Apple Developer account, so I do not need to send a request by e-mail. I just clicked on Save to disk and then on the Continue button. I saved the CSR file on your computer and completed the process of generating the Certificate Signing request.
Now, go back to the browser with instructions for the generation of CSR and click on Continue. I selected the .certSigningRequest
file saved on my Mac and clicked on the Generate button. Once the certificate generation is over, I downloaded a ready certificate on my computer and double-clicked on it to add to my Mac keychain.
At this stage, the generation of the certificate is completed. Now, you need to attach your project team. The Xcode project needs to be assigned to a team so that Xcode knows where to create your code signing and provisioning assets.
To assign the Xcode project to a team, follow these steps:
- In the project navigator, view the Identity settings.
- If necessary, select the target, click on General, and click on the disclosure triangle next to Identity to reveal the settings.
- Choose your team from the Team pop-up menu.
This message appears because we have not generated a Provisioning Profile yet.
Adding the application identifier
In order to generate a Provisioning Profile for our application, it must be registered with the Apple Developer Portal. To do this, on the presented Xcode screen, copy Bundle Identifier to the clipboard and switch to Apple Developer Portal. In the Identifiers section, press the + button. On the next page, you must enter the application Name and paste Bundle ID from the clipboard, as presented in the following screenshot:
After that, click on the Continue button, and on the next page, check the entered data and click on Submit. We added our application. Now, we need to register the device where we will be able to run our application.
Registering the device
To register the device in the Apple Developer Portal, go to Devices and click on the + button. On the form, you must enter the name of the device and its unique device identifier (UDID).
UDID can be found by connecting the Apple device to your computer in iTunes. If you go to the Device Manager tab and then to Summary, you will see the following screen:
Here, in the main section, you can copy the UDID by right-clicking on the UDID value. After that, go to the Apple Developer Portal, insert UDID, enter the Name of your device, and click on the Continue button:
Once the operation is complete, we will see our device in the Devices section. The next step is Provisioning Profile generation.
Generating a provisioning profile
To generate a Provisioning Profile for our application, go to the Provisioning Profiles | Development and press the + button. After that, select the iOS Development application type and click on Continue.
In the next step, we will choose our application, Travelly, and go to the next page. Select the certificate generated by us and move on to the next step. In this step, we will select the devices on which we want to run our application:
At this stage, I chose two devices. I want to be able to test our application on both devices.
Finally, go to the next page and enter a name of the Provisioning Profile. Let's enter Travelly. Complete the generation by pressing the Generate button. Then, we can download this Provisioning Profile, or allow Xcode to it.
Now, in Xcode, we need to select a proper Provisioning Profile. Follow these steps:
- In the project navigator, view the Identity settings.
- If necessary, select the target, click on Build Settings, and click on the disclosure triangle next to Code Signing to reveal the settings.
- Select Travelly as Provisioning Profile.
Alternatively, you can simply click on a provisioning profile, and it will be automatically installed in the Xcode.
That's all. Now, you can run the application on the device. Connect your device to your computer using the USB cable. Select the intended device from the toolbar's scheme menu; in my case, it is Cybind's iPhone. Press the Run button that appears in the same toolbar to the left of the scheme. This button builds, deploys, and runs the application in the device. We can see how the application started on our device.
Similarly, we can run the application on our device from the console:
$ cordova run ios
This command displays a lot of information because the Cordova CLI builds iOS projects using Xcode, which displays all the information about how it builds the application.
Congratulations! We have successfully executed our initial application on the real iOS device.