private launchIos()

in src/debugger/cordovaDebugSession.ts [605:705]


    private launchIos(launchArgs: ICordovaLaunchRequestArgs, projectType: ProjectType, runArguments: string[]): Promise<void> {
        if (os.platform() !== "darwin") {
            return Promise.reject<void>(localize("UnableToLaunchiOSOnNonMacMachnines", "Unable to launch iOS on non-mac machines"));
        }
        let workingDirectory = launchArgs.cwd;
        let errorLogger = (message) => this.outputLogger(message, true);

        this.outputLogger(localize("LaunchingApp", "Launching app (This may take a while)..."));

        let iosDebugProxyPort = launchArgs.iosDebugProxyPort || 9221;

        const command = launchArgs.cordovaExecutable || CordovaProjectHelper.getCliCommand(workingDirectory);
        // Launch the app
        if (launchArgs.target.toLowerCase() === TargetType.Device) {
            let args = ["run", "ios", "--device"];

            if (launchArgs.runArguments && launchArgs.runArguments.length > 0) {
                const launchRunArgs = this.addBuildFlagToArgs(launchArgs.runArguments);
                args.push(...launchRunArgs);
            } else if (runArguments && runArguments.length) {
                const runArgs = this.addBuildFlagToArgs(runArguments);
                args.push(...runArgs);
            } else {
                const buildArg = this.addBuildFlagToArgs();
                args.push(...buildArg);

                if (launchArgs.ionicLiveReload) { // Verify if we are using Ionic livereload
                    if (projectType.isIonic) {
                        // Livereload is enabled, let Ionic do the launch
                        // '--external' parameter is required since for iOS devices, port forwarding is not yet an option (https://github.com/ionic-team/native-run/issues/20)
                        args.push("--livereload", "--external");
                    } else {
                        this.outputLogger(CordovaDebugSession.NO_LIVERELOAD_WARNING);
                    }
                }
            }

            if (args.indexOf("--livereload") > -1) {
                return this.startIonicDevServer(launchArgs, args).then(() => void 0);
            }

            // cordova run ios does not terminate, so we do not know when to try and attach.
            // Therefore we parse the command's output to find the special key, which means that the application has been successfully launched.
            this.outputLogger(localize("InstallingAndLaunchingAppOnDevice", "Installing and launching app on device"));
            return cordovaRunCommand(command, args, launchArgs.allEnv, workingDirectory, this.outputLogger)
                .then(() => {
                    return CordovaIosDeviceLauncher.startDebugProxy(iosDebugProxyPort);
                })
                .then(() => void (0));
        } else {
            let target = launchArgs.target.toLowerCase() === TargetType.Emulator ? TargetType.Emulator : launchArgs.target;
            return this.checkIfTargetIsiOSSimulator(target, command, launchArgs.allEnv, workingDirectory).then(() => {
                let args = ["emulate", "ios"];
                if (projectType.isIonic) {
                    args.push("--");
                }

                if (launchArgs.runArguments && launchArgs.runArguments.length > 0) {
                    const launchRunArgs = this.addBuildFlagToArgs(launchArgs.runArguments);
                    args.push(...launchRunArgs);
                } else if (runArguments && runArguments.length) {
                    const runArgs = this.addBuildFlagToArgs(runArguments);
                    args.push(...runArgs);
                } else {
                    const buildArg = this.addBuildFlagToArgs();
                    args.push(...buildArg);

                    if (target === TargetType.Emulator) {
                        args.push("--target=" + target);
                    }
                    // Verify if we are using Ionic livereload
                    if (launchArgs.ionicLiveReload) {
                        if (projectType.isIonic) {
                            // Livereload is enabled, let Ionic do the launch
                            args.push("--livereload");
                        } else {
                            this.outputLogger(CordovaDebugSession.NO_LIVERELOAD_WARNING);
                        }
                    }
                }

                if (args.indexOf("--livereload") > -1) {
                    return this.startIonicDevServer(launchArgs, args).then(() => void 0);
                }

                return cordovaRunCommand(command, args, launchArgs.allEnv, workingDirectory, this.outputLogger)
                    .catch((err) => {
                        if (target === TargetType.Emulator) {
                            return cordovaRunCommand(command, ["emulate", "ios", "--list"], launchArgs.allEnv, workingDirectory).then((output) => {
                                // List out available targets
                                errorLogger(localize("UnableToRunWithGivenTarget", "Unable to run with given target."));
                                errorLogger(output[0].replace(/\*+[^*]+\*+/g, "")); // Print out list of targets, without ** RUN SUCCEEDED **
                                throw err;
                            });
                        }

                        throw err;
                    });
            });
        }
    }