执行此命令时:
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)中运行?
当前回答
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
其他回答
用于iPhone Xʀ模拟器
"iosxr": "react-native run-ios --simulator=\"iPhone Xʀ\"",
只需将此添加到您的脚本包。json文件
这里使用的字母“ʀ”和“R”是不同的Unicode。
然后点击$ yarn iosxr在iPhone Xʀ模拟器上启动应用程序
这里是改变iOS模拟器的新路径,你只需要改变
default: 'iPhone 6' or something else
路径:
<project_root>/node_modules/@react-native-community/cli/build/commands/runIOS/runIOS.js
使用此命令获取设备列表
xcrun simctl list devices
控制台
== Devices ==
-- iOS 13.5 --
iPhone 6s (9981E5A5-48A8-4B48-B203-1C6E73243E83) (Shutdown)
iPhone 8 (FC540A6C-F374-4113-9E71-1291790C8C4C) (Shutting Down)
iPhone 8 Plus (CAC37462-D873-4EBB-9D71-7C6D0C915C12) (Shutdown)
iPhone 11 (347EFE28-9B41-4C1A-A4C3-D99B49300D8B) (Shutting Down)
iPhone 11 Pro (5AE964DC-201C-48C9-BFB5-4506E3A0018F) (Shutdown)
iPhone 11 Pro Max (48EE985A-39A6-426C-88A4-AA1E4AFA0133) (Shutdown)
iPhone SE (2nd generation) (48B78183-AFD7-4832-A80E-AF70844222BA) (Shutdown)
iPad Pro (9.7-inch) (2DEF27C4-6A18-4477-AC7F-FB31CCCB3960) (Shutdown)
iPad (7th generation) (36A4AF6B-1232-4BCB-B74F-226E025225E4) (Shutdown)
iPad Pro (11-inch) (2nd generation) (79391BD7-0E55-44C8-B1F9-AF92A1D57274) (Shutdown)
iPad Pro (12.9-inch) (4th generation) (ED90A31F-6B20-4A6B-9EE9-CF22C01E8793) (Shutdown)
iPad Air (3rd generation) (41AD1CF7-CB0D-4F18-AB1E-6F8B6261AD33) (Shutdown)
-- tvOS 13.4 --
Apple TV 4K (51925935-97F4-4242-902F-041F34A66B82) (Shutdown)
-- watchOS 6.2 --
Apple Watch Series 5 - 40mm (7C50F2E9-A52B-4E0D-8B81-A811FE995502) (Shutdown)
Apple Watch Series 5 - 44mm (F7D8C256-DC9F-4FDC-8E65-63275C222B87) (Shutdown)
这里以不带ID的选择模拟器字符串为例。
iPad Pro(12.9英寸)(第四代)
最后的命令
iPhone
•iPhone 6s
react-native run-ios --simulator="iPhone 6s"
• 苹果手机 8
react-native run-ios --simulator="iPhone 8"
•iPhone 8 Plus
react-native run-ios --simulator="iPhone 8 Plus"
• 苹果手机 11
react-native run-ios --simulator="iPhone 11"
• 苹果手机 11 专业版
react-native run-ios --simulator="iPhone 11 Pro"
• iPhone 11 Pro Max
react-native run-ios --simulator="iPhone 11 Pro Max"
•iPhone SE(第二代)
react-native run-ios --simulator="iPhone SE (2nd generation)"
iPad
• iPad Pro(9.7 英寸)
react-native run-ios --simulator="iPad Pro (9.7-inch)"
•iPad(第7代)
react-native run-ios --simulator="iPad (7th generation)"
•iPad Pro(11英寸)(第二代)
react-native run-ios --simulator="iPad Pro (11-inch) (2nd generation)"
•第四代iPad Pro(12.9英寸)
react-native run-ios --simulator="iPad Pro (12.9-inch) (4th generation)"
•iPad Air(第三代)
react-native run-ios --simulator="iPad Air (3rd generation)"
使用——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:在模拟器上运行
正如Ian L所回答的,我也使用NPM来管理我的脚本。
例子: { "脚本":{ “ios”:“react-native run-ios——模拟器=\"iPad Air 2\"", “设备”:“xcrun simctl list设备” } }
这样,我可以很快得到我需要的东西:
列出所有设备:npm run devices 运行默认模拟器:npm Run ios