resolveSimulatorDevice function

Future<SimulatorDeviceResolution> resolveSimulatorDevice({
  1. String? deviceOverride,
})

Resolves the iOS simulator UDID that xcrun simctl commands should target.

Order of precedence:

  1. deviceOverride (--device <udid>) — must be an existing, booted simulator.
  2. The session device in .fdb/device.txt, when it is an iOS simulator. A session simulator that is not booted is an error: silently targeting another simulator would hit the wrong device. A session device that is not a simulator (Android, macOS, physical iOS) is ignored.
  3. The only booted simulator.

Never falls back to simctl's booted keyword, which picks an arbitrary device when more than one simulator is booted. With zero or several booted simulators and nothing to disambiguate, returns an error.

Implementation

Future<SimulatorDeviceResolution> resolveSimulatorDevice({String? deviceOverride}) async {
  final listing = await listSimulators();
  if (listing.error != null) {
    return (udid: null, error: listing.error);
  }
  return pickSimulatorDevice(
    listing.simulators!,
    deviceOverride: deviceOverride,
    sessionDevice: readDevice(),
  );
}