xcode 找不到 iPhone X 模拟器。使用 --verbose 标志运行 CLI 以获取更多详细信息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/56466024/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 10:57:35  来源:igfitidea点击:

Could not find iPhone X simulator. Run CLI with --verbose flag for more details

iosxcodereact-nativeios-simulator

提问by SinaMN75

I downloaded the recently released Xcode 11 beta version, and now I can't run my React-Native app on my simulator. I know there are some question on stack-overflow about this but they did'nt help. the problem is there is no

我下载了最近发布的 Xcode 11 测试版,现在我无法在我的模拟器上运行我的 React-Native 应用程序。我知道有一些关于堆栈溢出的问题,但他们没有帮助。问题是没有

/node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js

file at all. in the local-clifolder there is only one file named cli.js

文件。在local-cli文件夹中只有一个文件名为cli.js

'use strict';

var cli = require('@react-native-community/cli');

if (require.main === module) {
  cli.run();
}

module.exports = cli;

回答by JC Lango

error Could not find "iPhone X" simulator. Run CLI with --verbose flag for more details.

error Could not find "iPhone X" simulator. Run CLI with --verbose flag for more details.

PROBLEM

问题

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

如果您使用最新的 Xcode (11) 尝试此操作,则没有 iPhone X!

Run Simulator by itself, in the top menu, look under Hardware, Device, iOS 13.0.

自行运行模拟器,在顶部菜单中,查看硬件、设备、iOS 13.0。

You will see there is: - iPhone 8 - iPhone 8 Plus - iPhone XS - iPhone XS Max - iPhone XR - ... and some iPads

您会看到: - iPhone 8 - iPhone 8 Plus - iPhone XS - iPhone XS Max - iPhone XR - ... 和一些 iPad

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

当您执行 run-ios 时,react-native 旨在匹配请求的设备。

The internally hard coded default is iPhone X.

内部硬编码的默认值是 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

/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.

但是……实际上,第一个设备是手表,任何手表都被排除在匹配之外,所以这个函数会返回null。

SOLUTION 1 - Use Existing Xcode iOS Device

解决方案 1 - 使用现有的 Xcode iOS 设备

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

如上所述,首先单独运行 Simulator,并记下您想要的 iPhone 或 iPad。

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

然后将此名称作为可选参数传递给 run-ios 命令行命令,如下所示:

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

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

SOLUTION 2 - Add New Xcode iOS Device

解决方案 2 - 添加新的 Xcode iOS 设备

According to Xcode 11 Release Notes:

根据Xcode 11 发行说明

"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)"

“Xcode 不再默认创建所有可用的 iOS 模拟器设备。而是创建一组最常用的设备。要创建其他设备——或设备的多个实例——打开设备窗口,选择模拟器,单击 + 按钮,输入名称,选择相关设备类型和操作系统版本,在终端中执行xcrun simctl create命令,例如xcrun simctl create "My iPhone 7" "iPhone 7" iOS13.0. (49428617)"

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

在 Xcode 中,您需要添加一个名为“iPhone X”的新设备。

Also answered here:

也在这里回答:

error Could not find iPhone X simulator #418

错误找不到 iPhone X 模拟器 #418

回答by SHG21

If your project was created using react-native init, in your CLI< you should be able to type xcrun simctl list devicesto get a list of all available simulators. Scroll to the top to see list of available devices. If you want to run Simulator with say iPhone XS Max, then just; react-native run-ios --simulator="iPhone XS Max"

如果您的项目是使用 react-native init 创建的,则在您的 CLI< 中,您应该能够键入 xcrun simctl list devices以获取所有可用模拟器的列表。滚动到顶部以查看可用设备列表。如果您想使用 iPhone XS Max 运行模拟器,那么只需; react-native run-ios --simulator="iPhone XS Max"

回答by DanielSmurts

Adding the iPhone X simulator through the command line with:

通过命令行添加 iPhone X 模拟器:

/Applications/Xcode.app/Contents/Developer/usr/bin/simctl create "iPhone X" com.apple.CoreSimulator.SimDeviceType.iPhone-X com.apple.CoreSimulator.SimRuntime.iOS-13-0

solved the issue for me.

为我解决了这个问题。

回答by crapbox

I too was stuck at this for a long time.One way to solve this is by making changes in the node_modules folder. Steps below.

我也被困在这个问题上很长时间。解决这个问题的一种方法是在 node_modules 文件夹中进行更改。下面的步骤。

  1. Go to node_modules/@react-native-community/cli/build/commandsand open findMatchingSimulator.js
  2. Find the function findMatchingSimulator
  3. Once you go through the function, you will see that this function is returning the first matching simulator for opening your project.
  4. There is a line where we iterate over the devices and check if the device is available.
  5. Put a console.log before this check to get the details of each device.

       for (const i in device) {
           const simulator = device[i]; // Skipping non-available simulator
           console.log(JSON.stringify(simulator));
    
           if (simulator.availability !== '(available)' && simulator.isAvailable !== 'YES') 
           {
            continue;
           }
           ...................
    
  6. Now run your react-native run-ioscommand. You will see all the simulator device details getting printed in the console. Pick the one you like and replace return nullwith your desired simulator.

    In my case :

    return {
        udid: "E345U7U8-2213-11WQ-443D-OOJU7865P8J1",
        name: "iPhone 11",
        booted : false,
        version : null
      }

  1. 前往node_modules/@react-native-community/cli/build/commands并打开findMatchingSimulator.js
  2. 查找函数 findMatchingSimulator
  3. 完成该函数后,您将看到该函数正在返回第一个匹配的模拟器以打开您的项目。
  4. 有一行我们遍历设备并检查设备是否可用。
  5. 在此检查之前放置一个 console.log 以获取每个设备的详细信息。

       for (const i in device) {
           const simulator = device[i]; // Skipping non-available simulator
           console.log(JSON.stringify(simulator));
    
           if (simulator.availability !== '(available)' && simulator.isAvailable !== 'YES') 
           {
            continue;
           }
           ...................
    
  6. 现在运行你的react-native run-ios命令。您将看到在控制台中打印的所有模拟器设备详细信息。选择您喜欢的一个并替换return null为您想要的模拟器。

    就我而言:

    return {
        udid: "E345U7U8-2213-11WQ-443D-OOJU7865P8J1",
        name: "iPhone 11",
        booted : false,
        version : null
      }

Run react-native run-iosagain

react-native run-ios再次运行

回答by Muhammad Owais

Try this

尝试这个

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

回答by Tum Kiatbanjong

go to Xcode > Open Developer tool > simulator > Add Simulator

转到 Xcode > 打开开发者工具 > 模拟器 > 添加模拟器

回答by Kendall Crouch

I've got the same issue. Tried playing with the beta and got bit. I was able to open the .xcodeproj file in Xcode 10 and then run the simulator. I could then make changes in Atom and refresh the app in the simulator.

我有同样的问题。尝试玩测试版并有所收获。我能够在 Xcode 10 中打开 .xcodeproj 文件,然后运行模拟器。然后我可以在 Atom 中进行更改并在模拟器中刷新应用程序。

回答by csb00

I made an update today to xcode, July 26 2019, and I got the same message. I did a simple reboot of the iMac, ran "react-native run-ios" and it was up and the simulator was up and running!

我今天在 2019 年 7 月 26 日对 xcode 进行了更新,但收到了相同的消息。我对 iMac 进行了简单的重启,运行了“react-native run-ios”,它启动了,模拟器也启动并运行了!