simctl | fbsimctl : Simulator becomes unresponsive if booted after shutdown command - ios

I'm trying to achieve some automation for iOS simulators. I'm facing a strange issue that I'm not able to understand. Precisely following is my scenario:
I create a simulator using command: xcrun simctl create "iPhone 8 Plus"
I rename my newly created simulator: xcrun simctl rename <udid> my-new-iphone-8-plus
I boot my simulator: xcrun simctl boot <udid>
I open the simulator app: open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/. At this point the simulator app is up and running and I can fully interact with the simulator.
I shutdown the simulator: xcrun simctl shutdown <udid>. At this point the simulator gets shutdown but the simulator app is still running, which makes sense because I may be running more than one simulators simultaneously.
I boot the shutdown simulator again: xcrun simctl boot <udid>. At this point the simulator launches quickly. Neither the boot screen appears nor any loading indicator, as it appeared the first time I launched it.
At this moment the simulator is not responsive to my touch. It seems like it's stuck. The command returns successfully and doesn't return any errors.
I have tried the same thing using fbsimctl as well. I faced the same issue. Also tried with multiple simulators.
ONE IMPORTANT THING: When I close the simulator manually by selecting the desired simulator window and then do CMD + W or close it from the top left red close button and then boot it again from command line it surprisingly works fine.
OBJECTIVE: When the simulator is booted after shutdown using command line, the simulator should be responsive like it was before.
I tried other things as well, like killing process using pid. It didn't help.
Any help in this regard will be highly appreciated. Thanks!

Related

Lost connection to the debugger on "iPhone" Launching App Xcode 11.3.1

I've been experiencing this issue a lot with Xcode 11.3.1 when launching the App on the simulator, sometimes just restarting Xcode works, sometimes I have to restart my computer in order to make the app run again. It never happened on Xcode 11.1 tho.
I have noticed that on the simulator i got an error regarding "com.apple.commcenter.coretelephony.xpc". So the fix was to run this in terminal:
xcrun simctl spawn booted log config --mode "level:off" --subsystem com.apple.CoreTelephony
The downside is that you lose the auto layout warnings.
https://stackoverflow.com/a/54692253/4041884

Change default running simulator - react-native?

I want to change default simulator when building my app,
I'm trying to run this command react-native run-ios --simulator='iPhone XR'
but it's ignoring me :D and just launch iPhone X I don't know why?
when I open Xcode and choose what simulator i want then press Run icon it's work fine, but i don't need open Xcode every time i want to build my app, it's hart my Pc lo
The Simulator you are trying in command might not be available in your simulators list.
You can check the list of simulators list with the command:
xcrun simctl list
Also, you can start the simulator from the list with command without opening the xcode like:
xcrun simctl boot 4050BA57-C65E-4EDD-9CB3-38AAA9379912
4050BA57-C65E-4EDD-9CB3-38AAA9379912 is the UUID of the simulator you will get it from list.
With React Native to change the default simulator you can try to change the value of --simulator option from node-modules/react-native/local-cli/runIOS.js file
It will be by default like this:
{
command: '--simulator [string]',
description: 'Explicitly set simulator to use',
default: 'iPhone Xʀ',
}
You can change that iPhone Xʀ to your required simulator.
As you are making these changes inside the node-modules it might get changed or affected after npm or yarn install.

How do I get 'react-native-cli' to run my app in the specified hardware?

The React Native CLI will not run the specified simulator. When I enter
/usr/local/bin/node /usr/local/lib/node_modules/react-native-cli run-ios ‑‑simulator="iPhone X"
the simulator runs as expected, but insists on running in an iPhone 6, regardless of what simulator I specify, and if I select an additional hardware from the simulator app's menu, the one that launches does not show my project. (In fact, if I an iPhone X, it shows an app that I worked on some time ago instead.)
I've uninstalled and reinstalled the react-native-cli, and have no additional global ios-sim (though I had one once).
How do I get react-native-cli to run my app in the specified hardware?
My starting place for encountering these errors is simply (1) to install react-native-cli, (2) install WebStorm, (3) build a default React Native project there, and (4) run the project using the default iOS run configuration there. (WebStorm 2018.1.5; macOS 10.13.5; React Native CLI 2.0.1; Node 10.6.0)
The CLI goes through a few simple steps which you can step through here.
The first parameter is the output of running this from the command line:
xcrun simctl list --json devices
A few things to check first after running the xcrun command above:
Do you see multiple child nodes that start with 'iOS'? If so, you may have multiple versions of the simulators installed. The CLI will only look at the first version that it finds that starts with 'iOS'. So if there is only one simulator in that particular version, you're going to get that one all the time.
Find the iPhone 6 simulator, does it show it's state as Booted? If so, it will take priority if a simulator name is not provided
Is the iPhone X simulator availability listed as (available)?
Did you reboot the computer to kill any stale simulator processes? This should also reset the state and availability statuses of the simulators
Other than that, the cli does a pretty simple check:
If a simulator is Booted and no name is provided, start that one.
Launch the first simulator in the list if no name match was found using the name property

Waiting for {simulator/device} to start

With Xcode 9.3 (beta), I'm facing an issue with Xcode tool, while I try to build/run the application (project) for the first time, after Xcode launch/start.
Several times, it prevents project build with the message on status bar:
Waiting for iPhone-X to start
While my simulator is already started and working (There is no any activity, going on, in the simulator).
Here is reference snapshot:
As a temporary solution, I force close Xcode (9.3) and start again.
Is there anyone facing the same issue with Xcode 9.3 beta?
Update: Same issue in Xcode 9.3-Beta 2 also.
Here is How I fixed:
Due to quirks (most likely Simulator bugs) in the Simulator launching on both Xcode 8 and 9, there is no common code to have it launch successfully on both Xcodes. Through experimenting, I have found these to be most reliable:
Xcode 9:
killall Simulator
xcrun simctl boot <device_id>
open `xcode-select -p`/Applications/Simulator.app
Xcode 8:
killall Simulator
xcrun simctl shutdown booted
xcrun instruments -w <device_id>
refer: [iOS 11][Xcode 9] launch, install, start hangs Simulator #209
What (most of the time) works for me, is first launch it on a device. Kill it and then run it on a simulator.
Make sure you don't have the previous Xcode's version of Simulator running when you attempt to run Simulator from the new Xcode, because Xcode will attempt to use that one. (each Xcode bundles it's own Simulator)
Shut down the old Simulator, and try again.
Also, make sure in Xcode > Preferences > Locations > Command Line Tools is pointing to the current Xcode build.
What worked for me : open the simulator device manually (File -> Open Device -> pick the one). Then restart it by going to Device -> restart.
Then try rerunning on xcode.
I've experienced this lots of times especially in beta releases, until I discovered a 'hack' or perhaps a nice way to prevent such issue. But before that, I might add as well this SO link that has a compilation of .dmg Xcode download links. How to download Xcode DMG or XIP file?
TL;DR In order to prevent this kind of issue, just stop debugging or click on STOP button before building/running your application.

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