forked from appium/node-simctl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush.ts
More file actions
38 lines (37 loc) · 1.29 KB
/
push.ts
File metadata and controls
38 lines (37 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import {rimraf} from 'rimraf';
import {randomUUID} from 'node:crypto';
import path from 'node:path';
import os from 'node:os';
import fs from 'node:fs/promises';
import type {Simctl} from '../simctl';
/**
* Send a simulated push notification
*
* @since Xcode 11.4 SDK
* @param payload The object that describes Apple push notification content.
* It must contain a top-level "Simulator Target Bundle" key with a string value matching
* the target application's bundle identifier and "aps" key with valid Apple Push Notification values.
* For example:
* {
* "Simulator Target Bundle": "com.apple.Preferences",
* "aps": {
* "alert": "This is a simulated notification!",
* "badge": 3,
* "sound": "default"
* }
* }
* @throws {Error} if the current SDK version does not support the command
* or there was an error while pushing the notification
* @throws {Error} If the `udid` instance property is unset
*/
export async function pushNotification(this: Simctl, payload: Record<string, any>): Promise<void> {
const dstPath = path.resolve(os.tmpdir(), `${randomUUID()}.json`);
try {
await fs.writeFile(dstPath, JSON.stringify(payload), 'utf8');
await this.exec('push', {
args: [this.requireUdid('push'), dstPath],
});
} finally {
await rimraf(dstPath);
}
}