Перейти к содержимому
CloudClick iOS

Apps & sessions

Open, switch to and terminate apps, and query their state. Opening and switching both go through client.session, which also sets up the automation session.

client.session#

Open (or switch to) the app and set up an automation session for it. Usually called at the top of a script.

typescript
client.session(bundleId: string): Client;

Параметры

ПараметрТипОбязательныйПо умолчаниюОписание
bundleIdstringДа—The app's bundle ID, for example com.apple.Preferences (Settings).

Возвращаемое значение

ТипОписание
ClientA client bound to the new session. You rarely need it: keep using the global client, which follows the current session on its own.

Примечания

  • A locked device is unlocked first (only works without a passcode).

Пример

javascript
client.session('com.apple.Preferences');
sleep(2);
clickElement('label', 'General', 5);

См. также client.appTerminate、client.appCurrent

client.appTerminate#

Terminate the app's process. To start every round from the app's initial state, terminate it and then open it with client.session.

typescript
client.appTerminate(bundleId: string): object;

Параметры

ПараметрТипОбязательныйПо умолчаниюОписание
bundleIdstringДа—The app's bundle ID, for example com.apple.Preferences (Settings).

Возвращаемое значение

ТипОписание
objectThe raw WDA response; rarely needed.

Пример

javascript
client.appTerminate('com.zhiliaoapp.musically');
sleep(randomFloat(1, 2));
client.session('com.zhiliaoapp.musically');

См. также client.session

client.appState#

Query the app's run state.

typescript
client.appState(bundleId: string): { value: number };

Параметры

ПараметрТипОбязательныйПо умолчаниюОписание
bundleIdstringДа—The app's bundle ID, for example com.apple.Preferences (Settings).

Возвращаемое значение

ТипОписание
{ value: number }value is the state: 1 not running, 2 suspended in the background, 3 running in the background, 4 in the foreground.

Пример

javascript
var state = client.appState('com.zhiliaoapp.musically');
if (state.value !== 4) {
  client.session('com.zhiliaoapp.musically');
}

См. также client.appCurrent

client.appCurrent#

Information about the app in the foreground.

typescript
client.appCurrent(): { bundleId: string; name: string; pid: number };

Возвращаемое значение

ТипОписание
{ bundleId, name, pid }The foreground app's bundle ID, name and process ID.

Пример

javascript
var app = client.appCurrent();
logi(app.bundleId);

См. также client.appState

isAppInstalled#

Whether an app is installed on this device.

typescript
isAppInstalled(bundleId: string): boolean;

Параметры

ПараметрТипОбязательныйПо умолчаниюОписание
bundleIdstringДа—The app's bundle ID, for example com.apple.Preferences (Settings).

Возвращаемое значение

ТипОписание
booleanTrue when installed (running or not), false when not.

Исключения

ИсключениеКогда возникает
WDAErrorINVALID_ARGUMENTbundleId is missing or not a string.

Примечания

  • If the check itself fails (for example the device's automation service does not answer) it throws instead of returning false, so the script does not take the wrong branch.

Пример

javascript
if (!isAppInstalled('com.zhiliaoapp.musically')) {
  loge('TikTok is not installed');
  return false;
}
client.session('com.zhiliaoapp.musically');

См. также appList、client.appState

appList#

The apps running right now, in the foreground or background. This is not the list of installed apps; use isAppInstalled for that.

typescript
appList(): { pid: number; bundleId: string }[];

Возвращаемое значение

ТипОписание
{ pid, bundleId }[]The process ID and bundle ID of each running app.

Пример

javascript
var apps = appList();
for (var i = 0; i < apps.length; i++) {
  logi(apps[i].bundleId);
}

См. также isAppInstalled、client.appCurrent