Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`react-native run-ios` returns Error: Could not find iPhone X simulator

People also ask

How do you run on iOS device react native?

Open your react native app's directory, navigate to ios folder, and double-click on . xcworkspace file to open the Xcode. Next, open the Product menu, go to Destination, and select your device. If you don't have an Apple Developer account, you must create one to be able to run your project on an iOS device.


To fix this error, simply reinstall project & node modules using npm

npm install

Then it will show a list of warnings, and to fix them use the following command:

npm audit fix

This should fix everything, and allow you to run iOS emulator react-native run-ios


Edited: I copied your devices section of your output JSON and embedded to my own /node_modules/react-native/local-cli/runIOS/runIOS.js

function runOnSimulator(xcodeProject, args, scheme) {
return new Promise(resolve => {
    try {
        var simulators = {devices section of your json}; //Here
    } catch (e) {
        console.log("e", e);
        throw new Error('Could not parse the simulator list output');
    }

    const selectedSimulator = findMatchingSimulator(simulators, args.simulator);
    console.log("selected", selectedSimulator);
    if (!selectedSimulator) {
        throw new Error(`Could not find ${args.simulator} simulator`);
    }
    ...

And finally, it gave the same error as yours. So I figured out that parsing version of devices different. In your devices, version is;

"com.apple.CoreSimulator.SimRuntime.tvOS-12-1" //for tvOS
"com.apple.CoreSimulator.SimRuntime.iOS-12-1" // for iOS

but in react-native checks this version values like this(/node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js);

// Making sure the version of the simulator is an iOS or tvOS (Removes Apple Watch, etc)
if (!version.startsWith('iOS') && !version.startsWith('tvOS')) {
    continue;
}

So react-native can not recognize.
If we change this code with this;

// Making sure the version of the simulator is an iOS or tvOS (Removes Apple Watch, etc)
if (!version.startsWith('com.apple.CoreSimulator.SimRuntime.iOS') && !version.startsWith('com.apple.CoreSimulator.SimRuntime.tvOS')) {
    continue;
}

the problem was solved. I checked that with your JSON data in my computer and it worked.


PROBLEM

If you try this with the latest Xcode (11), there is no iPhone X!

Run Simulator by itself, in the top menu, look under Hardware, Device, iOS 13.0. You will see there is:

  • iPhone 8
  • iPhone 8 Plus
  • iPhone XS
  • iPhone XS Max
  • iPhone XR
  • ... and some iPads

When you execute run-ios, react-native is designed to match a requested device.

The internally hard coded default is iPhone X.

The function that tries to match the requested device is in:

/node_modules/@react-native-community/cli-platform-ios/build/commands/runIOS/findMatchingSimulator.js

This function is designed so you can give it a device, and an optional version number.

If the given device and version cannot be found, it will return a match using the first device in the list by default.

But... in reality, the first device is a watch, and any watch is excluded from matching, so this function will return null.

SOLUTION 1 - Use an existing Xcode device

Run Simulator first by itself, as described above, and make a note of which iPhone or iPad you want.

Then pass this name as an optional argument the the run-ios command line command as follows:

react-native run-ios --simulator="iPhone 8"

SOLUTION 2 - Add New Xcode iOS Device

According to Xcode 11 Release Notes:

"Xcode no longer creates every available iOS simulator device by default. Instead a set of the most commonly used devices are created. To create other devices — or multiple instances of a device — open the Devices window, select Simulators, click the + button, enter a name, and select the relevant device type and OS version. In Terminal, execute the xcrun simctl create command, for example xcrun simctl create "My iPhone 7" "iPhone 7" iOS13.0. (49428617)"

In Xcode, you need to add a new device called "iPhone X".

Also I answered here: React Native Issue #2328


Temporary fix:

Step 1: Open the file /node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js

Step 2: Change a line of code, from this:

if (!version.startsWith('iOS') && !version.startsWith('tvOS')) {
  continue;
}

to this:

if (!version.startsWith('com.apple.CoreSimulator.SimRuntime.iOS') && !version.startsWith('com.apple.CoreSimulator.SimRuntime.tvOS')) {
  continue;
}

Step 3: Run react-native run-ios (you might need to run it twice, and don't forget to kill the Metro Bundler [the console that's running in the background] if it's running from your previous unsuccessful build!)

The problem was that after an update to Xcode - the simulator namespaces were added to the devices' versions list. The React Native build wasn't expecting these namespaces - hence the build break.


after update to Xcode 11 xcrun returns true or false and not YES or NO as before.

goto /node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js and in

find

if (
   simulator.availability !== '(available)' &&
   simulator.isAvailable !== 'YES'
 ) {
  continue;
}

and change it to

if (
   simulator.availability !== '(available)' &&
   simulator.isAvailable !== true
 ) {
  continue;
}

There is no iPhone X simulator on your machine, most probably because you updated Xcode. You can simply pass the name of the available simulator like below:

react-native run-ios --simulator="iPhone 11"

For checking available simulators you can open Xcode and check on device list as shown below:

enter image description here