diff --git a/docs/commands.md b/docs/commands.md index 2c4b9e156..fda097471 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -404,6 +404,8 @@ Notes: If selected simulator does not exist, cli will try to run fallback simula Notes: `simulator_name` must be a valid iOS simulator name. If in doubt, open your AwesomeApp/ios/AwesomeApp.xcodeproj folder on XCode and unroll the dropdown menu containing the simulator list. The dropdown menu is situated on the right hand side of the play button (top left corner). +Notes: You can pass `booted` as the `simulator_name` to launch the currently booted simulator. + Example: this will launch your project directly onto the iPhone XS Max simulator: ```sh diff --git a/packages/cli-platform-ios/src/commands/runIOS/index.ts b/packages/cli-platform-ios/src/commands/runIOS/index.ts index 99fe43cf2..2d396a073 100644 --- a/packages/cli-platform-ios/src/commands/runIOS/index.ts +++ b/packages/cli-platform-ios/src/commands/runIOS/index.ts @@ -154,18 +154,35 @@ async function runOnSimulator( 'iPhone 12', 'iPhone 11', ]; - const selectedSimulator = fallbackSimulators.reduce((simulator, fallback) => { - return ( - simulator || findMatchingSimulator(simulators, {simulator: fallback}) - ); - }, findMatchingSimulator(simulators, args)); - if (!selectedSimulator) { - throw new CLIError( - `No simulator available with ${ - args.simulator ? `name "${args.simulator}"` : `udid "${args.udid}"` - }`, - ); + let selectedSimulator; + + if (args.simulator && args.simulator === 'booted') { + Object.values(simulators.devices).forEach((devices) => { + const bootedSimulator = devices.find(({state}) => state === 'Booted'); + + if (bootedSimulator) { + selectedSimulator = bootedSimulator; + } + }); + + if (!selectedSimulator) { + throw new CLIError('No booted simulator found.'); + } + } else { + selectedSimulator = fallbackSimulators.reduce((simulator, fallback) => { + return ( + simulator || findMatchingSimulator(simulators, {simulator: fallback}) + ); + }, findMatchingSimulator(simulators, args)); + + if (!selectedSimulator) { + throw new CLIError( + `No simulator available with ${ + args.simulator ? `name "${args.simulator}"` : `udid "${args.udid}"` + }`, + ); + } } /**