执行此命令时:

react-native run-ios

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

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

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


当前回答

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

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

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

rn-ios美元

其他回答

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

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

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

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

用于iPhone Xʀ模拟器

    "iosxr": "react-native run-ios --simulator=\"iPhone Xʀ\"",

只需将此添加到您的脚本包。json文件

这里使用的字母“ʀ”和“R”是不同的Unicode。

然后点击$ yarn iosxr在iPhone Xʀ模拟器上启动应用程序

正如Ian L所回答的,我也使用NPM来管理我的脚本。

例子: { "脚本":{ “ios”:“react-native run-ios——模拟器=\"iPad Air 2\"", “设备”:“xcrun simctl list设备” } }

这样,我可以很快得到我需要的东西:

列出所有设备:npm run devices 运行默认模拟器:npm Run 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