From 959f5fa3a26a69a7cc8563756e3b281d3f466116 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Wed, 24 Jul 2024 08:43:28 +0200 Subject: [PATCH] iOS: Simplify starting simulator We do not need different code paths for Xcode < 9 nowadays. Just tell simctl too boot the requested device and make sure the Simulator app is running. This also fixes an issue if for some reason a different device is already booted without the Simulator app running, e.g. 1. make sure Simulator is not running 2. boot a device from the command line with `xcrun simctl boot ` (get the device ID from the Devices & Simulators window in Xcode) 3. start Qt Creator and run an application on a *different* simulator device Without this patch Simulator app opens with the device from (2) and deployment of the application fails for the different device. With this patch the device for (3) is booted and the application deployed and run. Change-Id: Ifce8c470f2d4d646295ca4e47fbd92308f87adf8 Reviewed-by: Marcus Tillmanns --- src/plugins/ios/simulatorcontrol.cpp | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/plugins/ios/simulatorcontrol.cpp b/src/plugins/ios/simulatorcontrol.cpp index 1b6d121cd10..59c78e9f62d 100644 --- a/src/plugins/ios/simulatorcontrol.cpp +++ b/src/plugins/ios/simulatorcontrol.cpp @@ -108,23 +108,16 @@ static expected_str launchSimulator(const QString &simUdid, std::function< const FilePath simulatorAppPath = IosConfigurations::developerPath() .pathAppended("Applications/Simulator.app/Contents/MacOS/Simulator"); - if (IosConfigurations::xcodeVersion() >= QVersionNumber(9)) { - // For XCode 9 boot the second device instead of launching simulator app twice. - QString psOutput; - expected_str result = runCommand({"ps", {"-A", "-o", "comm"}}, &psOutput, shouldStop); - if (!result) - return result; + // boot the requested simulator device + const expected_str bootResult = runSimCtlCommand({"boot", simUdid}, nullptr, shouldStop); + if (!bootResult) + return bootResult; - for (const QString &comm : psOutput.split('\n')) { - if (comm == simulatorAppPath.toString()) - return runSimCtlCommand({"boot", simUdid}, nullptr, shouldStop); - } - } - const bool started = Process::startDetached( - {simulatorAppPath, {"--args", "-CurrentDeviceUDID", simUdid}}); - if (!started) - return make_unexpected(Tr::tr("Failed to start simulator app.")); - return {}; + // open Simulator.app if not running yet + return runCommand( + {"/usr/bin/open", + {IosConfigurations::developerPath().pathAppended("Applications/Simulator.app").nativePath()}}, + nullptr); } static bool isAvailable(const QJsonObject &object)