使用React Native打开iOS iPad模拟器

20

使用 react-native run-ios 命令测试 React Native 应用程序时,会打开一个 iPhone 模拟器。

您可以在模拟器选项中更改虚拟设备为 iPad,但是 React Native 应用程序不会出现在已安装应用程序列表中。

是否有一种方法可以从命令行界面打开 iPad 模拟器?

2个回答

39

--simulator标记是您要寻找的内容。

例如,react-native run-ios --simulator 'iPad 2' 将在 iPad 2 模拟器上运行应用程序。

另外,如果您需要获取可用模拟器列表及其名称,请使用xcrun simctl list devices


1
如果你有iPad 2 iOS 8.4和iPad 2 iOS 9.3,你该如何在这个命令中指定iOS版本? - iosdude
1
xcrun simctl list devices 在设备列表中显示有 iPad Pro,但是 react-native run-ios --simulator "iPad Pro" 却报错:Could not find iPad Pro simulator,为什么? - Jayraj
3
嘿@Jayraj,希望你已经解决了这个问题,但我遇到了同样的问题。解决方案是:--simulator="iPad Pro (12.9-inch)" - jdonald
我认为命令已经改变了,以前只需写“iPad Air”就可以了,但现在需要写“iPad Air(第四代)”。我有一堆旧格式的脚本! - Friis1978

19
使用此命令获取设备列表。
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"

• iPhone 8

react-native run-ios --simulator="iPhone 8"

• iPhone 8 Plus

->

• iPhone 8 Plus

react-native run-ios --simulator="iPhone 8 Plus"

• iPhone SE(第二代)

react-native run-ios --simulator="iPhone SE (2nd generation)"

iPad

• 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)"

• iPad(第7代)

react-native run-ios --simulator="iPad (7th generation)"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接