Your First iOS & SwiftUI App: Polishing the App
Mar 1 2022 · Swift 5.5, iOS 15, Xcode 13
Part 4: A Second Screen
41. Run the App on Your Own Device
Leave a rating/review
So far, you’ve run the app on the Simulator. That’s nice and all but probably not why you’re learning iOS development. You want to make apps that run on real iPhones and iPads!
In my opinion, one of the coolest things about iPhone development is being able to write an app, and carry it around in your pocket to show off to your family and friends.
Don’t get me wrong: developing your apps on the Simulator works very well. When developing, I spend most of my time with the Simulator and only test the app on my iPhone every so often.
However, you do need to run your creations on a real device in order to test them properly. There are some things the Simulator simply cannot do. For example, if your app needs the iPhone’s accelerometer, you have no choice but to test that functionality on an actual device. Please don’t start shaking your Mac.
In the old days, you needed a paid Developer Program account to run apps on your iPhone. These days, however, you can do it for free. All you need is an Apple ID. And the latest Xcode makes it easier than ever before.
Let’s give it a shot!
Connect iPhone, iPod Touch, or iPad to Mac using a USB cable
Window\Devices and Simulators
Click Device to select
“If this is the first time you’re using the device with Xcode, the Devices window will say something like, “iPhone is not paired with your computer.” To pair the device with Xcode, you need to unlock the device first (hold the home button). After unlocking, an alert will pop up on the device asking you to trust the computer you’re trying to pair with. Tap on Trust to continue.
Xcode will now refresh the page and let you use the device for development. Give it a few minutes (see the progress bar in the main Xcode window). If it takes too long, you may need to unplug the device and plug it back in.
At this point it’s possible to get the error message, “An error was encountered while enabling development on this device.” You’ll need to unplug the device and reboot it. Make sure to restart Xcode before you reconnect the device.”
“The next step is setting up your Apple ID with Xcode. It’s OK to use the same Apple ID that you’re already using with iTunes and your iPhone, but if you run a business, you might want to create a new Apple ID to keep things separate. Of course, if you’ve already registered for a paid Developer Program account, you should use that Apple ID.”
- \ Add Apple ID - sign in
“Note: It’s possible that Xcode is unable to use the Apple ID your provided - for example, if it has been used with a Developer Program account in the past that is now expired. The simplest solution is to make a new Apple ID. It’s free and only takes a few minutes. https://appleid.apple.com”
Project Settings\Signing & Capabilities
Click on Team to select your Apple ID.
Explain that you could get an error if you have the same bundle ID
If you get an error that says No Devices Registered, make sure your iPhone is connected first
Select Device and run
If you get a popup “codesign wants to sign using key” - click Always Allow.