ios Xcode 6 - 从命令行启动模拟器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26031601/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode 6 - Launch simulator from command line
提问by Balaji Sekar
I want to launch iPhone simulator from command line.
我想从命令行启动 iPhone 模拟器。
until now I have been using the below command
直到现在我一直在使用下面的命令
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app/Contents/MacOS/iPhone Simulator -SimulateDevice
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app/Contents/MacOS/iPhone Simulator -SimulateDevice
-SimulateDevice is used to launch a specific device type
-SimulateDevice 用于启动特定的设备类型
Now with Xcode 6 the path and the app has been changed to
现在使用 Xcode 6,路径和应用程序已更改为
/Applications/Xcode.app/Contents/Developer/Applications/iOS Simulator.app/Contents/MacOS/iOS Simulator
/Applications/Xcode.app/Contents/Developer/Applications/iOS Simulator.app/Contents/MacOS/iOS Simulator
but sadly -SimulateDevice option is not working now. I can launch the simulator, but dont have an option to specify which one to launch
但遗憾的是 -SimulateDevice 选项现在不起作用。我可以启动模拟器,但没有选项来指定要启动哪个
Anyone found any alternatives for this with Xcode 6?
有人在 Xcode 6 中找到了任何替代方案吗?
回答by Balaji Sekar
Found a way to achieve what I wanted.
找到了一种方法来实现我想要的。
Apple has introduced an interesting tool with Xcode 6!
Apple 在 Xcode 6 中引入了一个有趣的工具!
simctl
simctl
simclt allows you to control the simulator that are running.
simclt 允许您控制正在运行的模拟器。
run xcrun simctl
to get the list of available subcommands. Lots of new options to play around with.
运行xcrun simctl
以获取可用子命令的列表。有很多新选项可以玩。
Now to do what I wanted, here is the command to launch the simulator:
现在做我想做的,这是启动模拟器的命令:
xcrun instruments -w "iPhone 5 (8.0 Simulator)"
xcrun instruments -w "iPhone 5 (8.0 Simulator)"
-w is to provide a device type and to get the list of available devices.
-w 是提供设备类型并获取可用设备列表。
Just execute this:
只需执行这个:
xcrun instruments -s
xcrun instruments -s
After launching the simulator you can control it using simctl
启动模拟器后,您可以使用 simctl
To install your app:
要安装您的应用程序:
xcrun simctl install booted <app path>
xcrun simctl install booted <app path>
To launch the app:
要启动应用程序:
xcrun simctl launch booted <app identifier>
xcrun simctl launch booted <app identifier>
Hope this helps.
希望这可以帮助。
回答by Jeremy Huddleston Sequoia
With Xcode 6, if you want to have the iOS Simulator.app boot a specific device when it launches, you can run this from the command line:
使用 Xcode 6,如果您想让 iOS Simulator.app 在启动时启动特定设备,您可以从命令行运行它:
open -a "iOS Simulator" --args -CurrentDeviceUDID <DEVICE UDID>
open -a "iOS Simulator" --args -CurrentDeviceUDID <DEVICE UDID>
where you can figure out the UDID of the device you want to boot from:
您可以在其中找出要从中启动的设备的 UDID:
xcrun simctl list
xcrun simctl list
With Xcode 7, the application was renamed Simulator.app, so you should update the above accordingly to:
在 Xcode 7 中,应用程序被重命名为 Simulator.app,因此您应该相应地将上述内容更新为:
open -a Simulator --args -CurrentDeviceUDID <DEVICE UDID>
open -a Simulator --args -CurrentDeviceUDID <DEVICE UDID>
回答by TinyTimZamboni
For xcode 7:
对于 xcode 7:
open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app --args -CurrentDeviceUDID <DeviceUDID>
open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app --args -CurrentDeviceUDID <DeviceUDID>
Get your simulator udid's from xcrun simctl list
获取您的模拟器 udid 来自 xcrun simctl list
回答by Javier Rojano
To launch a simulator with a specific device booted I′m using list devicessubcommand to get the list of all devices available
要启动带有特定设备的模拟器,我正在使用list devices子命令来获取所有可用设备的列表
$ xcrun simctl list devices
== Devices ==
-- iOS 11.2 --
iPhone 5s (E3B6EA43-C805-49C2-9502-A44A465D8DF2) (Shutdown)
iPhone 6 (801E9E11-CA86-473A-9879-4B0742B827FB) (Shutdown)
iPhone 6 Plus (24013349-1A6F-489C-9A68-ABB00EBB4BBF) (Shutdown)
iPhone 6s (1A594D75-146C-4BEA-A250-1FADE7886114) (Shutdown)
iPhone 6s Plus (C2730FA0-11CB-49C9-A087-CB3C1BF1CC3D) (Shutdown)
iPhone 7 (F58B3749-3276-49E5-81C8-EBA1AEA7B242) (Shutdown)
iPhone 7 Plus (98167D8C-8F27-404C-AB02-588D9AAFD071) (Shutdown)
iPhone 8 (96322368-F763-4E0A-8576-ADE9F678211F) (Shutdown)
iPhone 8 Plus (E916D1EE-B67B-4C01-B3F5-C5C80CC4CDF8) (Shutdown)
iPhone SE (ABEFEDDF-7A7C-4B94-9E91-E065170FA47F) (Shutdown)
iPhone X (84DAB7AB-3CA2-4F5B-8C4E-A5B54CA15C31) (Shutdown)
iPad Air (DCD8CF4B-2C9F-4BA1-952A-ACB9CAD0A84D) (Shutdown)
iPad Air 2 (A47C9A05-233F-450F-9A39-318258E9ADEA) (Shutdown)
iPad (5th generation) (819C058E-64AC-4E73-8F41-2C0F919F8B56) (Booted)
this command will output a list of available devices with its UDIDs and statuses
此命令将输出可用设备列表及其 UDID 和状态
Then I launch the simulator app specifying a device with the -CurrentDeviceUDID option
然后我启动模拟器应用程序,指定一个带有 -CurrentDeviceUDID 选项的设备
/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator -CurrentDeviceUDID <DEVICE-UDID>
NOTE: replace the with a valid UDID from the list.
注意:用列表中的有效 UDID 替换 。
For example, if we want to launch the simulator with an Ipad (% generation booted):
例如,如果我们想用 Ipad 启动模拟器(% 代启动):
/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator -CurrentDeviceUDID 84DAB7AB-3CA2-4F5B-8C4E-A5B54CA15C31
UPDATE 23/05/2018
更新 23/05/2018
With Xcode 9.3 CurrentDevice UDID option is not working for me, as a workaround, I have to use simctl to boot the device in the simulator before open it.
使用 Xcode 9.3 CurrentDevice UDID 选项对我不起作用,作为一种解决方法,我必须在打开它之前使用 simctl 在模拟器中启动设备。
xcrun simctl boot 2BF01FC0-7E29-4AF1-ADD1-886DF129A9A9
open -a Simulator
You can create, erase, delete, boot, shutdown and upgrade simulators using simctl.
您可以使用 simctl 创建、擦除、删除、启动、关闭和升级模拟器。
$ xcrun simctl create
Usage: simctl create <name> <device type id> <runtime id>
$ xcrun simctl delete
Usage: simctl delete <device> [... <device n>] | unavailable
To get the list of valid device typesand runtimes
获取有效设备类型和运行时的列表
xcrun simctl list devicetypes
xcrun simctl list runtimes
回答by Neenu
You can specify the hardware and iOS version with -w flag. The format is
您可以使用 -w 标志指定硬件和 iOS 版本。格式是
instruments -w "simulator-version"
For eg:
例如:
instruments -w "iPhone Retina (3.5-inch) - Simulator - iOS 7.1"
.
instruments -w "iPhone Retina (3.5-inch) - Simulator - iOS 7.1"
.
You will get the available hardvare-iOS combinations by using the instruments -w help
command.
您将通过使用该instruments -w help
命令获得可用的硬件-iOS 组合。
回答by Estev?o Lucas
To boot a simulator:
启动模拟器:
xcrun simctl boot "iPhone X"
It will boot as a headless mode. To make the simulator visible:
它将作为无头模式启动。要使模拟器可见:
open -a Simulator
xcrun simctl boot
is simpler than xcrun instruments -w
. instruments
requires the full device name.
xcrun simctl boot
比 简单xcrun instruments -w
。instruments
需要完整的设备名称。
回答by Alex Zavatone
Verified in Xcode 9.4.1
在 Xcode 9.4.1 中验证
Device list in a REALLY NICE FORMAT:
~/Library/Developer/CoreSimulator/Devices/device_set.plist
非常好的格式的设备列表:
~/Library/Developer/CoreSimulator/Devices/device_set.plist
Root
DefaultDevices
com.apple.CoreSimulator.SimRuntime.iOS-8-4
com.apple.CoreSimulator.SimDeviceType.iPad-Retina : AB335FAF-E3E3-4AE9-A0AF-D1C6AEB5FBD4
Then you want to run (open) your Simulator app and make sure that a new instance of the app is launched.
然后,您要运行(打开)您的模拟器应用程序并确保启动该应用程序的新实例。
The app is here:
/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
该应用程序在这里:
/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
And the format you'd use is like this:
你使用的格式是这样的:
open -n -a <SimulatorPath> --args -CurrentDeviceUDID <SimDeviceTypeUDID>
open -n -a <SimulatorPath> --args -CurrentDeviceUDID <SimDeviceTypeUDID>
So, if I wanted to launch the Simulator above, I'd do this.
所以,如果我想启动上面的模拟器,我会这样做。
open -n -a /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app --args -CurrentDeviceUDID AB335FAF-E3E3-4AE9-A0AF-D1C6AEB5FBD4
open -n -a /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app --args -CurrentDeviceUDID AB335FAF-E3E3-4AE9-A0AF-D1C6AEB5FBD4
Hot damn! I just tested it and it works on Mac OS 10.11.6. Now the next trick is telling the Simulator to open our installed app. I'm not there yet. Hope this helps. Thanks to https://stackoverflow.com/users/726106/jeremy-huddleston-sequoiafor his detailed explanation.
热死了!我刚刚测试了它,它可以在 Mac OS 10.11.6 上运行。现在下一个技巧是告诉模拟器打开我们安装的应用程序。我还没到。希望这可以帮助。感谢https://stackoverflow.com/users/726106/jeremy-huddleston-sequoia的详细解释。
回答by Swapnil Mokashi
Run this command. The app will be restarted followed by changes. No need to rebuild it again.
运行此命令。该应用程序将重新启动,然后进行更改。无需再次重建它。
ios-sim "launch" "/Library/WebServer/Documents/testapp/build/iphone/build/Debug-iphonesimulator/test.app" "--devicetypeid" "iPad-2" "--exit";
For devicetypeid list:
对于 devicetypeid 列表:
ios-sim showdevicetypes