> ## Documentation Index
> Fetch the complete documentation index at: https://docs.run.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# Appearance, Permissions, and Push

> Switch dark mode, grant or reset app privacy permissions, and send simulated push notifications to iOS Simulator and Android Emulator sessions.

Put a session in the state your test needs before the app opens:

* **Appearance**: light or dark mode.
* **Permissions**: grant, revoke, or reset camera, location, notifications, and
  other privacy permissions for one app, so no system prompt interrupts the run.
* **Push** (iOS): deliver an APNs payload to an app, as if it came from Apple.

Each control works through the CLI, the TypeScript SDK, and the REST API, and
returns once the device has accepted it.

## Appearance

```bash CLI theme={null}
runcloud ios appearance "$IOS_SESSION_ID" dark --json
runcloud android appearance "$ANDROID_SESSION_ID" light --json
```

```ts TypeScript theme={null}
await cloud.ios.setAppearance(sessionId, "dark");
await cloud.simulators.setAppearance(androidSessionId, "light", { platform: "android" });
```

```bash REST theme={null}
curl -X POST "https://api.run.cloud/run-cloud/ios/$IOS_SESSION_ID/appearance" \
  -H "Authorization: Bearer $RUN_CLOUD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"mode": "dark"}'
```

iOS runs `simctl ui appearance`. Android runs `cmd uimode night yes|no`. Apps
that follow the system setting redraw at once. Some apps read it only at launch.

## Permissions

```bash CLI theme={null}
runcloud ios permissions grant "$IOS_SESSION_ID" --app com.example.App camera location notifications --json
runcloud ios permissions revoke "$IOS_SESSION_ID" --app com.example.App camera --json
runcloud android permissions reset "$ANDROID_SESSION_ID" --app com.example.app location --json
```

```ts TypeScript theme={null}
await cloud.ios.grantPermissions(sessionId, "com.example.App", ["camera", "location", "notifications"]);
await cloud.android.setPermission(androidSessionId, { app: "com.example.app", service: "camera", action: "revoke" });
```

```bash REST theme={null}
curl -X POST "https://api.run.cloud/run-cloud/ios/$IOS_SESSION_ID/permissions" \
  -H "Authorization: Bearer $RUN_CLOUD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"bundleId": "com.example.App", "service": "camera", "action": "grant"}'
```

The body takes `bundleId` (iOS) or `packageName` (Android), one `service`, and
an `action`: `grant`, `revoke`, or `reset`. `reset` returns the permission to
"not asked", so the app shows its prompt again. The CLI sends one request per
service and stops at the first failure.

| `service` | iOS | Android |
| - | - | - |
| `camera` | Yes | `CAMERA` |
| `microphone` | Yes | `RECORD_AUDIO` |
| `location` | While in use | `ACCESS_FINE_LOCATION` and `ACCESS_COARSE_LOCATION` |
| `location-always` | Always | Also `ACCESS_BACKGROUND_LOCATION` (API 29+) |
| `notifications` | Yes | `POST_NOTIFICATIONS` (API 33+; earlier versions need no grant) |
| `photos` | Yes | `READ_MEDIA_IMAGES` and `READ_MEDIA_VIDEO` (API 33+), else `READ_EXTERNAL_STORAGE` |
| `contacts` | Yes | `READ_CONTACTS` and `WRITE_CONTACTS` |
| `calendar` | Yes | `READ_CALENDAR` and `WRITE_CALENDAR` |
| `reminders`, `motion`, `media-library`, `siri` | Yes | No (`permission_service_unsupported`) |

On Android the app must be installed and must declare the permission in its
manifest. A grant does not survive an app reinstall.

## Push notifications (iOS)

Write an APNs payload with an `aps` object. The limit is 4 KiB, the same as
APNs.

```json payload.json theme={null}
{ "aps": { "alert": { "title": "Order shipped", "body": "Arrives Tuesday" }, "badge": 1, "sound": "default" } }
```

```bash CLI theme={null}
runcloud ios push "$IOS_SESSION_ID" --app com.example.App payload.json --json
cat payload.json | runcloud ios push "$IOS_SESSION_ID" --app com.example.App - --json
```

```ts TypeScript theme={null}
await cloud.ios.sendPush(sessionId, {
  app: "com.example.App",
  payload: { aps: { alert: { title: "Order shipped", body: "Arrives Tuesday" } } },
});
```

```bash REST theme={null}
curl -X POST "https://api.run.cloud/run-cloud/ios/$IOS_SESSION_ID/push" \
  -H "Authorization: Bearer $RUN_CLOUD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"bundleId": "com.example.App", "payload": {"aps": {"alert": "Hello"}}}'
```

The host gives the payload to `simctl push` as data. The app receives it as a
remote notification. Grant `notifications` first, or the banner does not
appear. A simulated push does not go through APNs, so it does not test your
server's APNs credentials or device tokens.

### Android

`POST /run-cloud/android/:id/push` returns **501** `push_unsupported`. Android
apps receive push messages through Firebase Cloud Messaging, and FCM delivery
needs Google Play services on the device. run.cloud does not pretend to deliver
one. To test push on Android, send a real FCM message from your own server to
the app's registration token, on an emulator image that has Google Play
services.

## Responses

A successful reply names the session, device, and lease, and echoes the change:

```json theme={null}
{ "ok": true, "platform": "ios", "sessionId": "…", "device": "…", "leaseId": "…",
  "permission": { "appId": "com.example.App", "service": "camera", "action": "grant" } }
```

`appearance` replies carry `"appearance": "dark"`. `push` replies carry
`"push": { "appId": "…", "payloadBytes": 87 }`.

## Validation

run.cloud checks every value before it reaches the device:

* `mode`, `service`, and `action` must be one of the values listed above.
* An app identifier must match `^[A-Za-z0-9._-]{1,255}$`.
* A push payload must be a JSON object with an `aps` object, at most 4096 bytes.

The device runs each control as a fixed command with these values as separate
arguments. It never builds a shell command from them.

## Errors

Failures return `ok: false`, `action` (`appearance`, `permissions`, or `push`),
and `error.code`:

| Code | HTTP | Meaning |
| - | - | - |
| `invalid_device_control` | 400 | A value is outside the allowed set, or the payload is invalid or too large. |
| `active_session_not_found` | 404 | The session is unknown, released, or belongs to another account. |
| `device_control_unsupported` | 422 | This simulator host cannot run the control yet. |
| `permission_service_unsupported` | 422 | The platform has no permission for that service. |
| `app_not_installed` | 422 | Android: the package is not installed. |
| `permission_not_declared` | 422 | Android: the app does not declare that permission. |
| `push_unsupported` | 501 | Push on Android. See above. |
| `device_control_failed` | 502 | The device rejected the command. Retry. |
| `device_control_timeout` | 504 | The device did not confirm in time. Retry. |
| `simulator_unavailable`, `device_control_transport_error`, `device_control_invalid_response` | 502/503 | The simulator host could not be reached or answered unexpectedly. Retry. |

## What is kept

Appearance and permissions stay set until you change them or the session ends.
A [saved state](https://docs.run.cloud/platform/simulator-state.md) does not include them, so set them
again after a restore.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.