Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions IOSDeviceLib/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ static const char *kCurrentApplicationsKey = "CurrentList";
static const char *kCommandKey = "Command";
static const char *kStatusKey = "Status";
static const char *kResponse = "response";
static const char *kPid = "pid";
static const char *kSocket = "socket";
static const char *kMessage = "message";
static const char *kResponseCommandType = "responseCommandType";
Expand Down
12 changes: 7 additions & 5 deletions IOSDeviceLib/DevicectlHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
using json = nlohmann::json;


json run_devicectl(std::string command){
json run_devicectl(std::string command, std::string app_arguments = ""){
char templatea[] = "/tmp/mytempfile-XXXXXX";
char* tempFileDir = mkdtemp(templatea);
std::string outputFile = std::string(tempFileDir) + "tempFileName";
std::string commandWithJson = command + " --quiet --json-output "+outputFile;
// devicectl hands everything after "--" to the launched app.
std::string commandWithJson = command + " --quiet --json-output " + outputFile + (app_arguments.empty() ? "" : " -- " + app_arguments);
std::string cmdResult = exec(commandWithJson.c_str());
FileInfo result = get_file_info(outputFile, true);
std::remove(outputFile.c_str());
Expand Down Expand Up @@ -66,12 +67,13 @@ bool devicectl_stop_application(std::string &executable, std::string &device_ide
}


bool devicectl_start_application(std::string &bundle_id, std::string &device_identifier, bool wait_for_debugger) {
bool devicectl_start_application(std::string &bundle_id, std::string &device_identifier, bool wait_for_debugger, int &pid) {

std::string command = "xcrun devicectl device process launch --device " + device_identifier + " --terminate-existing " + bundle_id + (wait_for_debugger?" --start-stopped":"");
std::string command = "xcrun devicectl device process launch --device " + device_identifier + " --terminate-existing " + bundle_id;

json result = run_devicectl(command);
json result = run_devicectl(command, wait_for_debugger ? "--nativescript-debug-brk" : "");
if(json_ok(result)){
pid = result.value("result", json()).value("process", json()).value("processIdentifier", -1);
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion IOSDeviceLib/DevicectlHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#include "Declarations.h"

bool devicectl_stop_application(std::string &executable, std::string &device_identifier);
bool devicectl_start_application(std::string &bundle_id, std::string &device_identifier, bool wait_for_debugger);
bool devicectl_start_application(std::string &bundle_id, std::string &device_identifier, bool wait_for_debugger, int &pid);
4 changes: 3 additions & 1 deletion IOSDeviceLib/IOSDeviceLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1748,8 +1748,10 @@ void start_app(std::string device_identifier,
kApplicationsCustomError);
} else {
if(check_xcode_major_version(15, device_identifier, method_id)){
if(devicectl_start_application(application_identifier, device_identifier, wait_for_debugger))
int pid = -1;
if(devicectl_start_application(application_identifier, device_identifier, wait_for_debugger, pid))
print(json({{kResponse, "Successfully started application"},
{kPid, pid},
{kId, method_id},
{kDeviceId, device_identifier}}));
else
Expand Down
9 changes: 8 additions & 1 deletion typings/interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ declare global {
response: string;
}

interface IStartApplicationResponse extends IDeviceResponse {
/**
* Process id of the started application, on devices running iOS 17 or later.
*/
pid?: number;
}

interface IDeviceMultipleResponse extends IDeviceId {
response: string[];
}
Expand Down Expand Up @@ -179,7 +186,7 @@ declare global {
postNotification(postNotificationArray: IPostNotificationData[]): Promise<IDeviceResponse>[];
awaitNotificationResponse(awaitNotificationResponseArray: IAwaitNotificatioNResponseData[]): Promise<IDeviceResponse>[];
apps(deviceIdentifiers: string[]): Promise<IDeviceAppInfo>[];
start(startArray: IIOSApplicationData[]): Promise<IDeviceResponse>[];
start(startArray: IIOSApplicationData[]): Promise<IStartApplicationResponse>[];
stop(stopArray: IIOSApplicationData[]): Promise<IDeviceResponse>[];
startDeviceLog(deviceIdentifiers: string[]): void;
startDeviceLogStream(logStreamArray: IDeviceLogStreamData[]): void;
Expand Down
Loading