@@ -23,23 +23,41 @@ const (
23
23
InterruptionLevelCritical EInterruptionLevel = "critical"
24
24
)
25
25
26
+ // LiveActivityEvent defines the value for the payload aps event
27
+ type ELiveActivityEvent string
28
+
29
+ const (
30
+ // LiveActivityEventUpdate is used to update an live activity.
31
+ LiveActivityEventUpdate ELiveActivityEvent = "update"
32
+
33
+ // LiveActivityEventEnd is used to end an live activity.
34
+ LiveActivityEventEnd ELiveActivityEvent = "end"
35
+ )
36
+
26
37
// Payload represents a notification which holds the content that will be
27
38
// marshalled as JSON.
28
39
type Payload struct {
29
40
content map [string ]interface {}
30
41
}
31
42
32
43
type aps struct {
33
- Alert interface {} `json:"alert,omitempty"`
34
- Badge interface {} `json:"badge,omitempty"`
35
- Category string `json:"category,omitempty"`
36
- ContentAvailable int `json:"content-available,omitempty"`
37
- InterruptionLevel EInterruptionLevel `json:"interruption-level,omitempty"`
38
- MutableContent int `json:"mutable-content,omitempty"`
39
- RelevanceScore interface {} `json:"relevance-score,omitempty"`
40
- Sound interface {} `json:"sound,omitempty"`
41
- ThreadID string `json:"thread-id,omitempty"`
42
- URLArgs []string `json:"url-args,omitempty"`
44
+ Alert interface {} `json:"alert,omitempty"`
45
+ Badge interface {} `json:"badge,omitempty"`
46
+ Category string `json:"category,omitempty"`
47
+ ContentAvailable int `json:"content-available,omitempty"`
48
+ InterruptionLevel EInterruptionLevel `json:"interruption-level,omitempty"`
49
+ MutableContent int `json:"mutable-content,omitempty"`
50
+ RelevanceScore interface {} `json:"relevance-score,omitempty"`
51
+ Sound interface {} `json:"sound,omitempty"`
52
+ ThreadID string `json:"thread-id,omitempty"`
53
+ URLArgs []string `json:"url-args,omitempty"`
54
+ ContentState map [string ]interface {} `json:"content-state,omitempty"`
55
+ DismissalDate int64 `json:"dismissal-date,omitempty"`
56
+ StaleDate int64 `json:"stale-date,omitempty"`
57
+ Event ELiveActivityEvent `json:"event,omitempty"`
58
+ Timestamp int64 `json:"timestamp,omitempty"`
59
+ AttributesType string `json:"attributes-type,omitempty"`
60
+ Attributes map [string ]interface {} `json:"attributes,omitempty"`
43
61
}
44
62
45
63
type alert struct {
@@ -81,6 +99,69 @@ func (p *Payload) Alert(alert interface{}) *Payload {
81
99
return p
82
100
}
83
101
102
+ // SetContentState sets the aps content-state on the payload.
103
+ // This will update content-state of live activity widget.
104
+ //
105
+ // {"aps":{"content-state": {} }}`
106
+ func (p * Payload ) SetContentState (contentState map [string ]interface {}) * Payload {
107
+ p .aps ().ContentState = contentState
108
+ return p
109
+ }
110
+
111
+ // SetDismissalDate sets the aps dismissal-date on the payload.
112
+ // This will remove the live activity from the user's UI at the given timestamp.
113
+ //
114
+ // {"aps":{"dismissal-date": DismissalDate }}`
115
+ func (p * Payload ) SetDismissalDate (dismissalDate int64 ) * Payload {
116
+ p .aps ().DismissalDate = dismissalDate
117
+ return p
118
+ }
119
+
120
+ // SetStaleDate sets the aps stale-date on the payload.
121
+ // This will mark this live activity update as outdated at the given timestamp.
122
+ //
123
+ // {"aps":{"stale-date": StaleDate }}`
124
+ func (p * Payload ) SetStaleDate (staleDate int64 ) * Payload {
125
+ p .aps ().StaleDate = staleDate
126
+ return p
127
+ }
128
+
129
+ // SetEvent sets the aps event type on the payload.
130
+ // This can either be `LiveActivityEventUpdate` or `LiveActivityEventEnd`
131
+ //
132
+ // {"aps":{"event": Event }}`
133
+ func (p * Payload ) SetEvent (event ELiveActivityEvent ) * Payload {
134
+ p .aps ().Event = event
135
+ return p
136
+ }
137
+
138
+ // SetTimestamp sets the aps timestamp on the payload.
139
+ // This will let live activity know when to update the stuff.
140
+ //
141
+ // {"aps":{"timestamp": Timestamp }}`
142
+ func (p * Payload ) SetTimestamp (timestamp int64 ) * Payload {
143
+ p .aps ().Timestamp = timestamp
144
+ return p
145
+ }
146
+
147
+ // SetAttributesType sets the aps attributes-type field on the payload.
148
+ // This is used for push-to-start live activities
149
+ //
150
+ // {"aps":{"attributes-type": attributesType }}`
151
+ func (p * Payload ) SetAttributesType (attributesType string ) * Payload {
152
+ p .aps ().AttributesType = attributesType
153
+ return p
154
+ }
155
+
156
+ // SetAttributes sets the aps attributes field on the payload.
157
+ // This is used for push-to-start live activities
158
+ //
159
+ // {"aps":{"attributes": attributes }}`
160
+ func (p * Payload ) SetAttributes (attributes map [string ]interface {}) * Payload {
161
+ p .aps ().Attributes = attributes
162
+ return p
163
+ }
164
+
84
165
// Badge sets the aps badge on the payload.
85
166
// This will display a numeric badge on the app icon.
86
167
//
@@ -218,7 +299,7 @@ func (p *Payload) AlertLaunchImage(image string) *Payload {
218
299
// specifiers in loc-key. See Localized Formatted Strings in Apple
219
300
// documentation for more information.
220
301
//
221
- // {"aps":{"alert":{"loc-args":args}}}
302
+ // {"aps":{"alert":{"loc-args":args}}}
222
303
func (p * Payload ) AlertLocArgs (args []string ) * Payload {
223
304
p .aps ().alert ().LocArgs = args
224
305
return p
0 commit comments