执行此命令时:
react-native run-ios
我的应用程序在iPhone6模拟器设备中默认运行:
Found Xcode project RN.xcodeproj
Launching iPhone 6 (9.2)...
如何在默认情况下让应用程序在不同的模拟器设备(如iPhone5s)中运行?
执行此命令时:
react-native run-ios
我的应用程序在iPhone6模拟器设备中默认运行:
Found Xcode project RN.xcodeproj
Launching iPhone 6 (9.2)...
如何在默认情况下让应用程序在不同的模拟器设备(如iPhone5s)中运行?
当前回答
这里是改变iOS模拟器的新路径,你只需要改变
default: 'iPhone 6' or something else
路径:
<project_root>/node_modules/@react-native-community/cli/build/commands/runIOS/runIOS.js
其他回答
修改/node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js的行代码
线55
if (
simulator.availability !== '(available)' &&
simulator.isAvailable !== true
) {
continue;
}
取代的:
if (
simulator.availability !== '(available)' &&
simulator.isAvailable !== true
) {
continue;
}
使用——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:在模拟器上运行
对于RN 0.64.2,配置位于node_modules/@react-native-community/cli-platform-ios/build/commands/runIOS/index.js,您可以修改文件中的默认模拟器
正如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