示例

1import { Button, List, Navigation, NavigationStack, Notification, Script, Section, } from "scripting"
2
3function Example() {
4  const dismiss = Navigation.useDismiss()
5
6  return <NavigationStack>
7    <List
8      navigationTitle={"Notification"}
9      navigationBarTitleDisplayMode={"inline"}
10      toolbar={{
11        cancellationAction: <Button
12          title={"Done"}
13          action={dismiss}
14        />
15      }}
16    >
17      <Section
18      >
19        <Button
20          title={"Schedule a Notification with actions"}
21          action={async () => {
22            Notification.schedule({
23              title: "Notification Testing",
24              body: "Long Press or Pull Down",
25              actions: [
26                {
27                  title: "Widget",
28                  url: Script.createRunURLScheme(Script.name, {
29                    doc: "Widget",
30                  })
31                },
32                {
33                  title: "LiveActivity",
34                  url: Script.createRunURLScheme(Script.name, {
35                    doc: "LiveActivity",
36                  })
37                }
38              ]
39            })
40          }}
41        />
42      </Section>
43
44      <Section
45      >
46        <Button
47          title={"Schedule a Notification with Rich Content"}
48          action={async () => {
49            Notification.schedule({
50              title: "Notification Testing",
51              body: "Long Press or Pull Down to show rich content.",
52              customUI: true,
53              userInfo: {
54                title: "AudioRecorder",
55                subtitle: "The interface allows you to record audio data to a file. It provides functionalities to start, stop, pause, and manage audio recordings, with configurable settings for audio quality, sample rate, format, and more.",
56              }
57            })
58          }}
59        />
60      </Section>
61    </List>
62  </NavigationStack>
63}
64
65async function run() {
66  await Navigation.present({
67    element: <Example />
68  })
69
70  Script.exit()
71}
72
73run()