Search code examples
iosios-simulator

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


I use open -n /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/ --args -CurrentDeviceUDID xxxxx to start a simulator alongside any number of others, and I can poll xcrun simctl list | grep xxxxx to find out when it's started its boot process.

How can I determine that the simulator has finished its boot-up process and is idling at its home screen?

Currently I'm polling ~/Library/Logs/iOS Simulator/{version}/system.log until it's quiet for a few seconds, but that's kinda lame.

Is there something nicer, like an xcrun simctl getenv?


Solution

  • You could poll the com.apple.springboard.services mach service for checkin. Eg:

    ~ $ 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
    

    edit: With recent builds, you can also run xcrun simctl bootstatus <UDID> to monitor this progress. That's likely a much more elegant solution than polling launchctl these days.

    edit (again): In addition to using 'xcrun simctl bootstatus ' to monitor the progress, you can use it to kick off the boot if it hasn't started already. Check xcrun simctl help bootstatus for more info.