首页 > 解决方案 > 找不到 iPhone 6(或任何其他)模拟器 React-Native,没有什么帮助?

问题描述

无法使用 iOS 模拟器运行我的项目

问题,

找不到 iPhone 6(或 X 或任何其他)模拟器

XCODE: 10.2
    react-native: 0.52
    react: ^16.0.0-alpha.12

这是我findMatchingSimulator.jsnodemodules/react-native/local-cli/runIOS:

/** * 版权所有 (c) 2015 年至今,Facebook, Inc. * 保留所有权利。* * 此源代码在此源代码树根目录中的 * LICENSE 文件中的 BSD 样式许可下获得许可。可以在同一目录中的 PATENTS 文件中找到额外授予的专利权。* */ 'use strict';

/** * 接受解析的模拟器列表和所需的名称,并返回一个具有匹配模拟器的对象。* * 如果simulatorName 参数为null,我们将进入默认模式并返回当前启动的模拟器,或者如果没有启动,它将是列表中的第一个。*

 * @param Object simulators a parsed list from `xcrun simctl list --json devices` command
 * @param String|null simulatorName the string with the name of desired simulator. If null, it will use the currently
 *        booted simulator, or if none are booted, the first in the list.
 * @returns {Object} {udid, name, version}
 */
function findMatchingSimulator(simulators, simulatorName) {
  if (!simulators.devices) {
    return null;
  }
  const devices = simulators.devices;
  var match;
  for (let version in devices) {
    // Making sure the version of the simulator is an iOS (Removes Apple Watch, etc)
    if (version.indexOf('iOS') !== 0) {
      continue;
    }
    for (let i in devices[version]) {
      let simulator = devices[version][i];
      // Skipping non-available simulator
      if (simulator.availability !== '(available)') {
        continue;
      }
      // If there is a booted simulator, we'll use that as instruments will not boot a second simulator
      if (simulator.state === 'Booted') {
        if (simulatorName !== null) {
          console.warn("We couldn't boot your defined simulator due to an already booted simulator. We are limited to one simulator launched at a time.");
        }
        return {
          udid: simulator.udid,
          name: simulator.name,
          version
        };
      }
      if (simulator.name === simulatorName && !match) {
        match = {
          udid: simulator.udid,
          name: simulator.name,
          version
        };
      }
      // Keeps track of the first available simulator for use if we can't find one above.
      if (simulatorName === null && !match) {
        match = {
          udid: simulator.udid,
          name: simulator.name,
          version
        };
      }
    }
  }
  if (match) {
    return match;
  }
  return null;
}

module.exports = findMatchingSimulator;

我尝试了不同的方法,但没有任何帮助。可用设备列表将 iPhone 指定为“不可用”</p>

标签: xcodereact-nativesimulator

解决方案


更改此行:

if (version.indexOf('iOS') !== 0) {

对此:

if (version.indexOf('com.apple.CoreSimulator.SimRuntime.iOS') !== 0) {

最近对 xcode 进行了更改,模拟器名称现在带有前缀。这为我解决了。


推荐阅读