执行此命令时:

react-native run-ios

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

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

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


当前回答

对于RN 0.64.2,配置位于node_modules/@react-native-community/cli-platform-ios/build/commands/runIOS/index.js,您可以修改文件中的默认模拟器

其他回答

使用——simulator标志指定一个模拟器。

以下是iOS 14.0之后可用的设备:

npx react-native run-ios --simulator="iPhone 8"
npx react-native run-ios --simulator="iPhone 8 Plus"
npx react-native run-ios --simulator="iPhone 11"
npx react-native run-ios --simulator="iPhone 11 Pro"
npx react-native run-ios --simulator="iPhone 11 Pro Max"
npx react-native run-ios --simulator="iPhone SE (2nd generation)"
npx react-native run-ios --simulator="iPhone 12 mini"
npx react-native run-ios --simulator="iPhone 12"
npx react-native run-ios --simulator="iPhone 12 Pro"
npx react-native run-ios --simulator="iPhone 12 Pro Max"
npx react-native run-ios --simulator="iPhone 13 Pro"
npx react-native run-ios --simulator="iPhone 13 Pro Max"
npx react-native run-ios --simulator="iPhone 13 mini"
npx react-native run-ios --simulator="iPhone 13"
npx react-native run-ios --simulator="iPod touch (7th generation)"
npx react-native run-ios --simulator="iPad Pro (9.7-inch)"
npx react-native run-ios --simulator="iPad (9th generation)"
npx react-native run-ios --simulator="iPad Air (4th generation)"
npx react-native run-ios --simulator="iPad Pro (11-inch) (3rd generation)"
npx react-native run-ios --simulator="iPad Pro (12.9-inch) (5th generation)"
npx react-native run-ios --simulator="iPad mini (6th generation)"

列出所有可用的iOS设备:

xcrun simctl list devices

目前没有办法设置默认值。

React Native Docs:在模拟器上运行

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

您可以在~/处创建别名。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