【问题标题】:React Native: Default iOS device inside simulatorReact Native:模拟器中的默认 iOS 设备
【发布时间】:2016-10-22 17:58:16
【问题描述】:

当运行一个 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 设备?

【问题讨论】:

标签: ios iphone reactjs react-native ios-simulator


【解决方案1】:

目前似乎没有办法设置默认值。 你可以用这个

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

在thread 中讨论的自定义模拟器上运行。

【讨论】:

    【解决方案2】:

    可以通过改变这个文件来设置默认值:

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

    【讨论】:

      【解决方案3】:

      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

      【讨论】:

        猜你喜欢
        • 2016-09-16
        • 2021-05-25
        • 2016-11-08
        • 1970-01-01
        • 1970-01-01
        • 2019-05-07
        • 2015-04-29
        • 2011-05-18
        • 2011-03-24
        相关资源
        最近更新 更多