执行此命令时:

react-native run-ios

我的应用程序在iPhone6模拟器设备中默认运行:

Found Xcode project RN.xcodeproj
Launching iPhone 6 (9.2)...

如何在默认情况下让应用程序在不同的模拟器设备(如iPhone5s)中运行?


当前回答

如果你想更改默认设备,只需要运行react-native run-ios,你可以在finder中搜索关键字“runios”,然后打开文件夹和固定index.js文件,将“iphone X”更改为你需要的设备。

[1]: https://i.stack.imgur.com/BCtR1.png

其他回答

你也可以通过在你的包的scripts元素中添加一个条目来使用npm。json文件。如。

"launch-ios": "react-native run-ios --simulator \"iPad Air 2\""

然后使用这个:运行launch-ios

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

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

2)打开react原生项目文件夹

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 start-iphone6

我有一个问题与XCode 10.2指定正确的iOS模拟器版本号,所以使用:

react-native run-ios --simulator='iPhone X (com.apple.CoreSimulator.SimRuntime.iOS-12-1)'

您可以在~/处创建别名。bash_profile文件:

alias rn-ios="react-native run-ios——模拟器\"iPhone 5s (10.0)\""

然后使用创建的别名运行react-native:

rn-ios美元

如果你想更改默认设备,只需要运行react-native run-ios,你可以在finder中搜索关键字“runios”,然后打开文件夹和固定index.js文件,将“iphone X”更改为你需要的设备。

[1]: https://i.stack.imgur.com/BCtR1.png