For the More Curious: Running an Application on a Device

Running apps on the simulator is useful, but it is not a substitute for running them on a hardware device. Hardware devices have additional capabilities (cameras, for example) and the performance of apps can vary between the simulator and a hardware device.

You will need an Apple Developer Program account to run apps on a device and submit apps to the App Store. A free account will allow you to run on a device, but you will not be able to submit apps to the App Store without a paid account. You can enroll in the Apple Developer Program at developer.apple.com/​programs/​enroll/.

There are four important items in the provisioning process:

Developer Certificate

This certificate file is added to your Mac’s keychain, which you can view in Keychain Access. It is used to digitally sign your code.

App ID

The application identifier is a string that uniquely identifies your application on the App Store. Application identifiers typically look like this: com.bignerdranch.AwesomeApp, where the name of the application follows the name of your company.

The App ID in your provisioning profile must match the bundle identifier of your application. A development profile can have a wildcard character (*) for its App ID and therefore will match any bundle identifier. To see the bundle identifier for the Quiz application, select the project from the top of the project navigator, then select the Quiz target. Finally, select the General pane from the menu across the top of the editor.

Unique Device ID (UDID)

This identifier is unique for each iOS device.

Provisioning Profile

This is a file that lives on your development device and on your computer. It references a Developer Certificate, a single App ID, and a list of the device IDs for the devices that the application can be installed on. This file is suffixed with .mobileprovision.

When an application is deployed to a device, Xcode uses a provisioning profile on your computer to access the appropriate certificate. This certificate is used to sign the application binary. Then, the development device’s UDID is matched to one of the UDIDs contained within the provisioning profile, and the App ID is matched to the bundle identifier. The signed binary is then sent to your development device, where it is confirmed by the same provisioning profile on the device and, finally, launched.

Managing these details yourself can be complicated, but thankfully Xcode can manage it all for you.

After you have registered for a developer account, you need to add the account to Xcode. Open Xcode and select XcodePreferences. Select the Accounts tab and click the For the More Curious: Running an Application on a Device button in the bottom-left corner. Choose Apple ID and then sign in to your developer account. Once you are done, you will see your account listed on the lefthand side (Figure 1.31).

Figure 1.31  Xcode account preferences

Xcode account preferences

Close the preferences window. Select the Quiz project in the project navigator, select the Quiz target, and then open the Signing & Capabilities pane. Make sure the Automatically manage signing checkbox is checked. Then, from the Team drop-down menu, select your developer account.

Plug in your device. You will be prompted on the device to trust your computer. Once you have done that, select the device from the active scheme pop-up menu (Figure 1.32); it should be at or near the top of the choices.

Figure 1.32  Choosing the device

Choosing the device

Back in the Signing & Capabilities pane, you will be asked to register the device to your developer account. Click Register Device, and Xcode will take care of the details. Once that is complete, your Signing & Capabilities pane will look similar to Figure 1.33.

Figure 1.33  Signing & Capabilities pane

Signing & Capabilities pane

At this point, you can build and run your application (Command-R), and it will appear on your device.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset