Building and launching app in Simulator from terminal

1.7k views Asked by At

I wanted to build and launch my iOS app using a shell script and not Xcode. My question is the similar to this question: How to launch an iOS app in the simulator without XCode rebuilding the app, which was asked in 2012.

It says that the IPA file created in build directory within the project directory can be used. I could not find a build directory inside my project folder. Also, I want to build the app from a script.

What is the most latest way of building and running an app on simulator using terminal commands?

Edit:

I built the app from command line:

xcrun xcodebuild \
  -scheme UITestingTutorial \
  -project UITestingTutorial.xcodeproj \
  -configuration Debug \
  -destination 'platform=iOS Simulator,name=iPhone 11,OS=13.6' \
  -derivedDataPath \
  build

But how do I launch it now?

1

There are 1 answers

0
Dracula On

Running this script inside your project directory will launch the app programmatically.

xcrun xcodebuild \
-scheme UITestingTutorial \
-project UITestingTutorial.xcodeproj \
-configuration Debug \
-destination 'platform=iOS Simulator,name=iPhone 11,OS=13.6' \
-derivedDataPath \
build

open -a "Simulator"

# This simulator id has been manually found
# by running 'xcrun simctl list' and searching
# for iPhone 11 under iOS 13.6 under Devices 
# A script can be written to automatically find this.
xcrun instruments -w 3100E7BC-0B95-4B3E-B0DC-8743FFCB731A
xcrun simctl install 3100E7BC-0B95-4B3E-B0DC-8743FFCB731A ./build/Build/Products/Debug-iphonesimulator/UITestingTutorial.app (http://uitestingtutorial.app/)
xcrun simctl launch 3100E7BC-0B95-4B3E-B0DC-8743FFCB731A com.codepro.UITestingTutorial

You can refer to Launch apps in iOS Simulator using Terminal for more details. Please note the xctool is deprecated.