我如何判断 iOS 模拟器何时启动到其主屏幕?

How can I tell when the iOS simulator has booted to its home screen?

我使用 open -n /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/ --args -CurrentDeviceUDID xxxxx 与其他任何数量的模拟器一起启动模拟器,我可以轮询 xcrun simctl list | grep xxxxx 以了解它何时开始启动过程。

如何确定模拟器已完成启动过程并在其主屏幕上空闲?

目前我正在轮询 ~/Library/Logs/iOS Simulator/{version}/system.log 直到它安静几秒钟,但这有点蹩脚。

有更好的东西吗,比如 xcrun simctl getenv

您可以轮询 com.apple.springboard.services mach 服务以进行签入。例如:

~ $ simctl spawn booted launchctl print system | grep com.apple.springboard.services
         0x1c407    M   D   com.apple.springboard.services
...
~ $ simctl spawn booted launchctl print system | grep com.apple.springboard.services
         0x1c407    M   A   com.apple.springboard.services

编辑: 对于最近的构建,您还可以 运行 xcrun simctl bootstatus <UDID> 来监控此进度。现在,这可能是比轮询 launchctl 更优雅的解决方案。

编辑(再次): 除了使用 'xcrun simctl bootstatus ' 来监控进度之外,您还可以使用它来启动尚未启动的启动。查看 xcrun simctl help bootstatus 了解更多信息。