diff --git a/src/errors.ts b/src/errors.ts index bae1fc4..cb122ec 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -78,10 +78,7 @@ export type AVDExceptionCode = typeof ERR_UNSUITABLE_API_INSTALLATION; export class AVDException extends AndroidException {} export type EmulatorExceptionCode = - | typeof ERR_ALREADY_RUNNING - | typeof ERR_AVD_HOME_NOT_FOUND - | typeof ERR_NON_ZERO_EXIT - | typeof ERR_UNKNOWN_AVD; + typeof ERR_ALREADY_RUNNING | typeof ERR_AVD_HOME_NOT_FOUND | typeof ERR_NON_ZERO_EXIT | typeof ERR_UNKNOWN_AVD; export class EmulatorException extends AndroidException {} @@ -98,10 +95,7 @@ export type SDKExceptionCode = export class SDKException extends AndroidException {} export type IOSRunExceptionCode = - | typeof ERR_TARGET_NOT_FOUND - | typeof ERR_NO_DEVICE - | typeof ERR_NO_TARGET - | typeof ERR_DEVICE_LOCKED; + typeof ERR_TARGET_NOT_FOUND | typeof ERR_NO_DEVICE | typeof ERR_NO_TARGET | typeof ERR_DEVICE_LOCKED; export class IOSRunException extends Exception {} diff --git a/src/ios/utils/simulator.ts b/src/ios/utils/simulator.ts index ebe8a4c..cc15c74 100644 --- a/src/ios/utils/simulator.ts +++ b/src/ios/utils/simulator.ts @@ -1,3 +1,4 @@ +import { pathExists } from '@ionic/utils-fs'; import { spawnSync } from 'child_process'; // TODO: need cross-spawn for windows? import * as Debug from 'debug'; @@ -85,11 +86,22 @@ export async function runOnSimulator(udid: string, appPath: string, bundleId: st const xCodePath = await getXCodePath(); debug(`Running simulator ${udid}`); - const openResult = spawnSync( - 'open', - [`${xCodePath}/Applications/Simulator.app`, '--args', '-CurrentDeviceUDID', udid], - { encoding: 'utf8' }, - ); + + const simulatorApp = `${xCodePath}/Applications/Simulator.app`; + const deviceHubApp = `${xCodePath}/../Applications/DeviceHub.app`; + + let openArgs: string[]; + + if (await pathExists(simulatorApp)) { + openArgs = [simulatorApp, '--args', '-CurrentDeviceUDID', udid]; + } else if (await pathExists(deviceHubApp)) { + openArgs = [`devices://device/open?id=${udid}`]; + } else { + throw new Exception(`Unable to find Simulator.app or DeviceHub.app in ${xCodePath}`); + } + + const openResult = spawnSync('open', openArgs, { encoding: 'utf8' }); + if (openResult.status) { throw new Exception(`There was an error opening simulator: ${openResult.stderr}`); }