React Native:模拟器内的默认 iOS 设备

React Native: Default iOS device inside simulator

当运行一个react native应用程序时,设备模拟器出于某种原因总是默认为iPhone 6,部分输出:

$ react-native run-ios
Found Xcode project AwesomeProject.xcodeproj
Launching iPhone 6 (9.3)...

模拟器为 运行 后,只能通过 Hardware>Device 菜单更改设备。

我已将 Xcode 设置为在模拟器中使用较旧的 iPhone 版本,但它只能在 IDE 中使用,而不能在 CLI 中使用。

如何在 CLI 中从 运行 到 react-native 更改默认 iOS 设备?

目前似乎无法设置默认值。 你可以使用这个

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

至 运行 在自定义模拟器上,如本 所讨论。

可以通过更改此文件来设置默认值:

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

此块可用于设置 iOS 模拟器、Xcode 方案和根项目位置:

const args = parseCommandLine([
    {
      command: 'simulator',
      description: 'Explicitly set simulator to use',
      type: 'string',
      required: false,
      default: 'iPhone 6',
    }, {
      command: 'scheme',
      description: 'Explicitly set Xcode scheme to use',
      type: 'string',
      required: false,
    }, {
      command: 'project-path',
      description: 'Path relative to project root where the Xcode project (.xcodeproj) lives. The default is \'ios\'.',
      type: 'string',
      required: false,
      default: 'ios',
    }
  ], argv);

1) 重命名您的模拟器,如果模拟器名称相同但 iOS 版本

Xcode -> Window -> Devices and Simulators -> Simulators.

2) 打开你的 React Native 项目文件夹

3) 编辑 package.json

"scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest",
    "flow": "node_modules/.bin/flow",
    "start-iphone6": "react-native run-ios --simulator \"iPhone 6 11.3\""
}

4) npm run start-iphone6