Change default running simulator - react-native? - ios

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.

Related

Not able to launch app in iOS simulator in vscode

I am new to vscode, I tried running my code in iOS simulator but its not showing the simulator in the first place.
the options i get are
view android emulators
view iOS simulators
But when I click on view iOS simulators I get a pop up saying
" Something went wrong fetching you iOS simulators! Make sure you have Xcode installed. Try running this command in your terminal: instruments -s devices "
You may need to run this command, when VSCode tries access the simulator there may be error which says
Cannot find "xcodebuild". Xcode 11.0.0 or greater is required to
develop for iOS. Encountered error while building for device.
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

Cannot select iOS Phone Simulator in Android Studio for Flutter

I have an issue. I started to code in Android Studio and I want to select iOS Simulator. However, I can select only option Open iOS Simulator which opens.. a watch!
How could I launch a phone as a simulator?
I tried going into Simulator itself, but couldn't find any ways how to do it.
Open iOS Simulator externally first. Now, open Xcode, Select your latest Xcode version in Xcode -> Preferences -> Locations -> Command Line Tools
Now, go to Terminal and run flutter doctor See if it shows any iOS device connected.
If yes, then you're done. Now you can see opened simulator can be seen in Flutter Device Selection and used to run your flutter application in iOS Simulator.
If No, then open terminal of project and run xcrun simctl list, from list of devices copy UID of wanted device and run xcrun simctl boot *SELECTED_UID*
After extensive research, I found a solution.
First, go to your xcode.
xcode -> Preferences -> Components and install selected iOS version.
After installation is finished, head to Android Studio go to Terminal tab and write xcrun simctl list - you will get list of devices. Select which one you want to use, copy UID (bunch of numbers) and use it with this command xcrun simctl boot *YOUR_DEVICE_ID*
Hope it helps for someone with same issue!

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

Run .app file in iOS 8 simulator

I have a .app file shared from a developer which i would like to run in iOS 8 simulator. I have seen similar questions which has solutions for older versions of iOS which is no longer working for iOS 8. Can someone point out what needs to be done to run the .app file in an iOS 8 simulator without using xcode.
Boot the simulator you want to install it to in the iOS Simulator and then do the following:
xcrun simctl install booted /path/to/Your.app
xcrun simctl launch booted com.yourcompany.yourapp
The "booted" token was not supported on older versions of simctl in Xcode 6.0. If you get an error, please use the full device UDID instead of "booted". You can determine the UDID by running xcrun simctl list
If the application crashes after installing in the simulator using the command,
xcrun simctl install booted /path/to/Your.app
It's probably because the architecture issues, since we used the device build instead of simulator build.
The basic architecture difference between the iphone simulator and iphone device is
iPhone simulator uses the architecture i386 or x86_x64
whereas,
iPhone device uses the architecture arm64 or armv7 or armv7s
We can find each device architectures in this link. So to over come this problem we need to get the simulator build by changing the xcode build location settings.
SOLUTION :
To change the build location settings, Open your xcode and follow the below steps.
Go to xcode preferences.
Choose the locations tab.
In the 'Derived Data:' section click 'advanced', from the resulting screen choose 'legacy'.
Now build the application, after successful build go to 'Your-App-Folder/build/Debug-iphonesimulator' in finder, and copy the build available on the same folder with the extension .app
Copy that and run the above command answered by #jeremy.
xcrun simctl install booted /path/to/Your.app
After running this command, note that your simulator is installed with the build you specified. There you go, run the application in simulator by clicking the corresponding app and use it.
I deliberately write this solution to help the needy, those who are clueless about the architecture issues specified above.
Happy Coding :)
iOS Simulator also supports dragging and dropping for installing .app files
Open Simulator
you can do it through XCode under XCode > Open Developer Tool > Simulator
to open it "without using xcode", see these answers.
Find the .app file in Finder and drag it into your Simulator window
Wait for the app to install and launch it
For developers looking to provide a simulator build to theirs testers, these are the steps that I followed to create and test a build -
Add i386 in valid architectures section of build settings.
Open terminal and navigate to your project folder. Then execute the command -
xcodebuild -arch i386 -sdk iphonesimulator8.1
(This will build the application)
To install the application on simulator, run the command mentioned in the above answer i.e -
xcrun simctl install booted /path/to/Your.app
Now you should be able to run the app by clicking on the installed application in the simulator.
I have followed all the above commands and stuff but none worked. All I was doing is creating .app through archiving the app from Product->Archive and then converting that generated .ipa to .app by changing the extension to .zip.
But the app is crashing as and when it is being launched.
For those facing the same issue, go to
DerivedData/projectname/Build/Products/Debug-iphonesimulator/
folder. There you can find the .app file with app name. You need to use this .app file by dragging and dropping onto the simulator. Product->Archive->.app doesn't work.

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