Adding a Physical Device as a Run Destination
To run applications you write in Xcode on your iPhone or iPad, a few one-time-only setup steps are required.
First, be sure Xcode is open.
Select the menu sequence Window → Devices and Simulators.
Then, connect your iPhone or iPad to your Mac using a cable.
The first time you do this, you will see an image something like this:
To test applications you write on a physical device the device must be in developer mode.
The instructions that follow are for iOS 16.
If you have an earlier version of iOS on your phone, try these instructions instead.
To do this, first open the Settings app, then select Privacy & Security:
Then select Developer Mode:
Then restart your iPhone:
Despite the warning about reduced device security, know that an application cannot be loaded on to your phone unless it is unlocked and you have explicitly indicated that you trust the developer who wrote the app.
After restarting your phone, you will see this message appear – select Turn on:
You will need to provide your device passcode:
Now that you have enabled developer mode on your phone, back in Xcode in the Devices and Simulators dialog, you will see a yellow banner message telling you that certain required files are being copied to and from your device:
That process may take a few minutes to complete; be patient. When it is finished, the yellow banner will disappear.
Next, you can select the device you've connected as a run destination.
At the top of the primary Xcode window, click the list of devices (1), then select your device from the list (2):
Now build the application:
Next, will likely see a message indicating that Xcode cannot run the application on the device, because, essentially, your iPhone or iPad currently does not "trust" the Mac that you are developing on to install applications upon it:
On your phone, you will see a message like this:
To create the necessary trust, follow these steps.
Open Settings again, and choose General:
Then select VPN & Device Management:
Under Developer App, you will see a profile tied to your LCS Apple ID – select that profile:
To run apps you make using your LCS Apple ID on your device, select the button as shown:
Finally, on the dialog that appears, select Trust:
The next time you build your application with your iPhone or iPad as the selected run destination, after a few seconds, you should see the app open on your device.
Have fun! 🚀