Getting Started with iOS Development
Apple requires the use of Xcode running on macOS to develop for iOS. The labs further require iOS 17.4 to run. This means your iPhone must be at least iPhone SE (2nd gen), Xr or later (use your browser search and search for “compatible”). You will need Xcode 15.3, which would require macOS Sonoma 14.4 for your development host, which would mean your Mac cannot be too old.
The iOS simulator is powerful but, unfortunately, it doesn’t simulate the camera nor magnetometer. Without physical access to a device, you can’t take photo/video nor read the magnetometer, which our labs have you do. So aside from requiring Xcode running on a mac, we also require that you have access to a physical iPhone to complete the last two of the five iOS labs.
If you have an iPhone but no Mac, you can try to get a loaner laptop from ITS or use the iMacs in the ITS Campus Computing sites or the Groundworks at MediaLabs to develop your labs.
In the Groundworks lab, the Macs under the signs
Recording Booth
andConversion Rack
do not have Xcode installed and cannot be used to complete the labs.If you are exploring other options to develop for iOS without a Mac, please review, Have iPhone but no Mac?.
Languages
We will use only Swift to develop iOS apps, not Objective-C. The course does not support cross-platform frameworks, including React Native and Flutter. All course projects must be built natively. If you are contemplating cross-platform mobile development, please consult our collection of articles on industry experiences with cross-platform solutions.
Developing iOS app
We assume:
- you have a device running iOS 17.4 or later.
check version
To check your iOS version, on your phone navigate to
Settings > General > About > Software Version
. - you will develop only in Swift, not Objective-C.
- you are running Xcode 15 or later.
- your entire team should be on the same version of Xcode, macOS, and iOS.
alternative IDEs
You can use a different IDE (such as VSCode or AppCode) or do your development on a different platform, but in the end you’ll still need Xcode running on macOS to build an iOS app. If you want to explore use of other IDE (not recommended), see references below.
Setting up Xcode
Installing Xcode:
- Open the App Store app on your Mac
- Search for and install Xcode
- Open and install all other components it asks for
Xcode may be buggy: if it does unexpected things, restart and see if malbehavior persists.
Optional tools
Xcode caches a lot of data to support different versions of the OS and to improve development speed. It also keeps logs and documentations. But it doesn’t clean up this data automatically. Over time, it will use up multiple GBs of your hard drive space. DevCleaner comes in handy in cleaning up unused Xcode data.
Xcode panes
- Left or Navigator: project and file explorer, warnings/errors, etc.
- Middle/main or Editor: editor and storyboard
- Right or Inspectors: various inspectors
- Bottom or Debug Area: console and debug output
You can open any side panels by selecting them under Xcode’s View
menu item.
You will notice single characters, such as ‘A’, ‘M’, ‘R’ showing up next to your source files. These indicate the file version control status, also used with git.
Documentation
The best way to find documentation on iOS API is in Xcode:
- Hold down the
option
key, - mouse over your code and, if information is available, your cursor will turn into a question mark,
- click on the highlighted code.
Or:
- Open the right panel,
- select the question mark icon,
- click on an object to see its documentation in the right panel.
Or:
-
Help > Developer Documentation (⇧⌘0)
.
See also Apple’s Xcode documentation for a thorough reference. (The older Xcode Help still contains some useful info.)
Product Name
When you create a new project, Xcode will prompt you for a Product Name
. Do not re-use the name of a SDK or library, such as Foundation
, UIKIt
, Combine
, or any other third-party SDKs/libraries you’re using. Otherwise, Xcode will complain of Cyclic dependency between modules ...
.
Running and debugging
On device
To turn on developer mode on your iPhone, it must first be connected to Xcode (as of iOS 17). Connect your device to your Mac with a USB cable and launch Xcode. In Xcode, on the top menu select Window > Devices and Simulators
(screenshot) and then your device. Then on your device, go to Settings > Privacy & Security > Developer Mode
and turn on Developer Mode
.
To run your code on device, select your device on the field at the center top of Xcode right pane (screenshot). Click the play icon at the top of the left pane to build and run.
If you allow WiFi connection to your physical device, it will be recognized faster when plugged in (downloading code via WiFi itself seems to be very slow). Click on device name > Add Additional Simulators
. Click on the Devices
button on top, and check Connect via network
. Once you connect your device to Xcode, Xcode can reload and launch your app on device through WiFi even if WiFi is turned off on your laptop!.
The first time you run your app on device, you may see Xcode error message saying, Could not launch "YOUR_APP"
due to “invalid code signature, inadequate entitlements or its profile has not been explicitly trusted by the user.”
- Click
OK
- On your device, navigate to
Settings > General > VPN & Device Management > Apple Development: YOUR_APPLE_ID > Trust "Apple Development: YOUR_APPLE_ID"
and tapTrust
- Run your app from Xcode again
If you get a popup on the iPhone with Untrustred Enterprise Developer
when installing the app (this could be an issue specific to Verizon-sourced phones) [thanks A. McCarthy F22 for finding the solution]:
- Click
Cancel
- On your device, navigate to
Settings > General > VPN & Device Management > Enterprise App > YOUR_ENTERPRISE > Trust "YOUR_ENTERPRISE"
and tapTrust
.
Should Xcode complain of, “Xcode was unable to read the required data from the device” or other unexpected error messages about connecting to the device, try ([stackoverflow]):
- Delete
~/Library/Developer/Xcode/iOS DeviceSupport
, the whole folder - Disconnect your device from your laptop and restart it
- Quit and restart Xcode
- Plug your device back in
If you get a Command CodeSign failed with a nonzero exit code
, try to “restart your mac. It will prompt you for your password for the login keychain signature when you build the project” [thanks A. McCarthy F22 for finding the stackoverflow article].
On a simulator
- Select the iPhone type on the top left of Xcode (iPhone SE 2020 is fine)
may need to download simulators separately to use them (you can also delete unnecessary simulators)
- Click play to build and run
- Simulator will boot iOS and load the app
- Click to interact or use Hardware menu for physical buttons
- Disable
Hardware > Keyboard > Connect Hardware Keyboard
to display the on-screen keyboard - Click the stop button on Xcode to close the app (not the simulator)
Running the labs on the iOS simulator
Chatter
There is no special set up necessary to run the basic Chatter
lab (lab0).
Audio
There is again no special set up necessary to run the Audio
lab. If you have multiple mics and speakers connected to your development host, on the simulator you can choose the input and output to use by selecting I/O > Audio Input
and I/O > Audio Output
respectively. You can also control the output volume under the I/O
menu or with keyboard shortcuts.
Signin
The iOS simulator has Touch ID (or Face ID, depending on iPhone model) simulation. Under the main menu, select Features > Touch/Face ID > Enrolled
to enroll. When prompted for biometric check, choose Features > Touch/Face ID > Matching Touch/Face
or Non-matching Touch/Face
to simulate matching or non-matching biometric ID. If you are prompted to enter the device’s PIN even after you have enrolled in Touch/Face ID, Quit the simulator and try again.
Authentication when accessing keychain item is done by Apple’s Secure Enclave. When the Secure Enclave carries out authentication, it first presents the biometric prompt. Unfortunately the iOS simulator does not simulate the Secure Enclave: accessing a secured keychain item always returns the item’s value without authentication. On the simulator, to prompt user with a simulated biometric prompt, we call Apple’s LocalAuthentication
framework.
Images
The iOS simulator supports picking photos and videos from the simulator’s album, but it does not support camera access. There is an iCimulator project that presents a mock video scene and photo on the iOS simulator much like how it is done on the Android emulator. While either the mock photo or the mock video can indeed be presented (but not both in the same build), the video record and take photo functions are not simulated. iCimulator is supposed to work with the Mac’s camera, but that is also no longer working. The Python streaming server to feed the camera exited due to an empty image_array
.
iCimulator further breaks the native photo/video picking function of the simulator.
Maps
You can simulate your location either within Xcode, by clicking on the arrow button in the debug console menu (screenshot), or on the simulator. To simulate your location on the simulator, select on its main menu, Features > Location > Custom Location
and enter the latitude and longitude of the location you want to simulate. If you choose Features > Location > City Run
, your simulated location should be set to “Cupertino” and your simulated speed should be “walking” speed. If you choose the option Location > Freeway Drive
and wait a couple of minutes between chatt
postings, you should see your location changed to a different city at “driving” speed. Unfortunately, there doesn’t seem to be a way to change the reported facing of the phone; the simulator doesn’t simulate the magnetometer.
Publishing an iOS app
TestFlight can be used for beta testing (even A/B test).
To publish your app:
- OBEY the numerous content restrictions on App Store Review Guidelines.
- Read also, This is Why Apple Would Reject Your App.
- Follow Apple’s instructions on Submit your iOS app to the App Store and the App Store Connect Help.
Reviews usually take a few days but could take a few weeks.
References
-
Xcode documentation
- and the older Xcode Help
Swift on other IDEs and OSs: in all cases, you eventually still need Xcode running on macOS to build iOS apps.
- AppCode
- iOS Development on VSCode (macOS) As far as I can tell, only this article shows you how to set up iOS (UIKit) API completion. The rest only works with the Swift programming language, not iOS SDKs.
- Introducing Swift for Visual Studio Code
- Swift Development with Visual Studio Code (macOS)
- Swift plugin for VSC (macOS and Linux)
- Swift Development with Visual Studio Code - On Linux!
- Introducing Swift on Windows
- sourcekit-lsp Editor Integration (other than VSC)
- Can I delete unnecessary device simulators of Xcode?
- Xcode Simulator: how to remove older unneeded devices?
- Get the biometric authentication prompt for protected keychain items in the iOS simulator
- iCimulator simulates camera functions on iOS simulator with images, videos, or the MacBook camera. No longer works.
- Differences between simulated and physical devices dated, audio input is now supported on the simulator.
- Why Android created emulator rather than simulator?
- Simulator or Emulator? What is the difference?
Publishing an iOS app
Prepared for EECS 441 by James Rogan, Sugih Jamin | Last updated: August 21st, 2024 |