xcrun simctl boot / uninstall hang when simulator isn't running - ios

I'm trying to use xcrun simctl to boot a device and uninstall an application, but it hangs on the uninstall step
xcrun simctl boot <deviceudid>
xcrun simctl uninstall <deviceudid> <bundleid>
and it hangs on uninstall and sits forever...however, if i have the simulator already running and execute
xcrun simctl uninstall <deviceudid> <bundleid>
it works fine...but i'm trying to do this in a script without opening the simulator manually

This happens because when you use 'xcrun simctl boot ...' you are not getting a full boot of the simulator. Some services (including those provided by the system app, like install or launch) are unavailable in this mode.
If you want to script booting the device in full, you'll probably want to refer to my answer in Xcode 6 - Launch simulator from command line

Related

How to launch an iOS simulator app from the command line

Is there a way to launch an app on the iOS simulator from the command line, like
simctl launch <app-package>
or something like that?
To install your app:
xcrun simctl install booted
To launch the app:
xcrun simctl launch booted
Hope this helps.

How to build Xcode project from the command line?

I've tried reading the Xcode Tools documentation Apple provides, so that I can use the Terminal to build a .app file and run the resulting app on the Simulator. Essentially what I want to do is do the same thing as Cmd + R does on Xcode.
So far I've attempted to build my .xcodeproj like this:
xcodebuild -configuration Debug build
However, when I install & run it on the Simulator I get an app w/ a black screen:
// Boot device
xcrun simctl boot "iPhone 7"
// Install app
xcrun simctl install "iPhone 7" "/Users/.../MyApp/build/Debug-iphoneos/MyApp.app"
// Open simulator
open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
// Launch app using its bundle id
xcrun simctl launch booted "com.example.apps.MyApp"
Not to mention the xcrun simctl launch booted "com.example.apps.MyApp" line never terminates and on the Simulator it keeps trying to open and reopen the app, but the app only ever shows a black screen.
If anyone could tell me what I'm doing wrong with the building of the.xcodeproj that would be great!
After having a working configuration in Xcode, open a shell and navigate to the directory, where your <NAME>.xcodeproj resides.
After running:
xcodebuild -list -project <NAME>.xcodeproj/
you see a list of Schemes.
Copy the desired scheme name and run:
xcodebuild -workspace <WORKSPACE NAME> -scheme <SCHEME NAME> build
You can install [ios-deploy][1] i.e. via:
npm install -g ios-deploy
Copy the app path from the end of the xcodebuild output and run:
ios-deploy --debug --bundle <APP PATH>
Now the app should be launched on i.e. a connected device.
[1]: https://github.com/phonegap/ios-deploy

Error shutting down simulator

In xcrun simctl documentation there is an entry:
xcrun simctl shutdown booted - Shutdown a device
Bun when I call it from command line, the simulator is not actually shut down but is freezed instead.
How this could be solved?
The only workaround I found is to kill the simulator by its Process ID.
killall "Simluator"
Simulator.app predates CoreSimulator and still assumes that it owns the entire boot lifecycle. You should only use 'simctl shutdown' for devices that you booted via 'simctl boot'.

How to uninstall an app from iPhone simulator using the command line?

I would like to uninstall or remove an iOS application from the command line. Let's say the application is call ApplicationName, so is there a way to do it from the command line?
From terminal, run:
xcrun simctl uninstall booted <app identifier>

How do I remove app from iOS 8 Simulator from command line?

I have an automation running in the iOS Simulator that I have to remove before another run. How do I remove the app from the iOS Simulator from the command line?
For each simulator device directory (located at ~/Library/Developer/CoreSimulator/Devices/*), I
tried to delete ./data/Containers/Bundle/Application/ and ./data/Containers/Data/Application/.
Even when I tried to delete the app by long pressing the app in the Simulator (the app becomes jiggly) and click on the X button, the user defaults were not being cleared. I want the app state to be 100% clean.
I found a good solution to solve this problem.
With Xcode 6.1, to uninstall an app, use the following command:
xcrun simctl uninstall booted com.example.apple-samplecode.UICatalog
where com.example.apple-samplecode.UICatalog is the bundle identifier of the application you wish to uninstall.
One approach that we found for deleting user defaults is to delete all files in the ./data/Library/Preferences/* in addition to deleting application and data directories.
However, in Xcode 6, the command xcrun has new subcommand called simctl that allows me to manage iOS Simulator including resetting the simulator, and installing the application.
The solution that I came up with is to use the command
xcrun simctl erase [device ID]
Example
If xcrun simctl list(†) returns
9DDA0CFE-7CEC-40B6-A343-1EC01F282B22 (active, disconnected)
Watch: Apple Watch Series 2 - 42mm (88474523-163E-4021-B591-2AECBFA26997) (Shutdown)
Phone: iPhone 7 Plus (5785E680-15CD-42D3-82AB-597286A270C5) (Shutdown)
then run these 2 commands
xcrun simctl erase 88474523-163E-4021-B591-2AECBFA26997
xcrun simctl erase 5785E680-15CD-42D3-82AB-597286A270C5
(†) The device ID can be obtained from running
xcrun simctl list
This will reset the simulator (equivalent to iOS Simulator > Reset Contents and Settings... menu item).
With Xcode 6.0.1 (Build 6A317), there is either a bug or a change in behavior where when you uninstall an application, user defaults are not removed.
Usage: simctl [--noxpc] [--set <set path>] <subcommand> ... | help [subcommand]
Command line utility to control the iOS Simulator
For subcommands that require a <device> argument, you may specify a device UDID
or the special "booted" string which will cause simctl to pick a booted device.
If multiple devices are booted when the "booted" device is selected, simctl
will choose one of them.
Subcommands:
create Create a new device.
delete Delete a device.
erase Erase a device's contents and settings.
boot Boot a device.
shutdown Shutdown a device.
rename Rename a device.
getenv Print an environment variable from a running device.
openurl Open a URL in a device.
addphoto Add a photo to the photo library of a device.
install Install an app on a device.
uninstall Uninstall an app from a device.
launch Launch an application by identifier on a device.
spawn Spawn a process on a device.
list List available devices, device types, or runtimes.
notify_post Post a darwin notification on a device.
icloud_sync Trigger iCloud sync on a device.
help Prints the usage for a given subcommand.
Reset all Content & Settings in a single command
Quit iPhone Simulator
In Terminal, run:
xcrun simctl erase all
This will reset content and settings of all the simulators for the active version of Xcode (the one referenced by xcode-select -p).
xcrun simctl uninstall simulatorIdentifier appBundleId

Resources