Skip to content

Commit cf67458

Browse files
Hilário Coelhoeveruribeappleboy
authored
Fixes #661: iOS interruption level support (#679)
Co-authored-by: Ever <[email protected]> Co-authored-by: Bo-Yi Wu <[email protected]>
1 parent 754e50d commit cf67458

File tree

4 files changed

+41
-32
lines changed

4 files changed

+41
-32
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ The Request body must have a notifications array. The following is a parameter t
655655
| mutable_content | bool | enable Notification Service app extension. | - | only iOS(10.0+). |
656656
| name | string | sets the name value on the aps sound dictionary. | - | only iOS |
657657
| volume | float32 | sets the volume value on the aps sound dictionary. | - | only iOS |
658+
| interruption_level | string | defines the interruption level for the push notification. | - | only iOS(15.0+) |
658659

659660
### iOS alert payload
660661

notify/notification.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,22 @@ type PushNotification struct {
101101
FastAppTarget int `json:"fast_app_target,omitempty"`
102102

103103
// iOS
104-
Expiration *int64 `json:"expiration,omitempty"`
105-
ApnsID string `json:"apns_id,omitempty"`
106-
CollapseID string `json:"collapse_id,omitempty"`
107-
Topic string `json:"topic,omitempty"`
108-
PushType string `json:"push_type,omitempty"`
109-
Badge *int `json:"badge,omitempty"`
110-
Category string `json:"category,omitempty"`
111-
ThreadID string `json:"thread-id,omitempty"`
112-
URLArgs []string `json:"url-args,omitempty"`
113-
Alert Alert `json:"alert,omitempty"`
114-
Production bool `json:"production,omitempty"`
115-
Development bool `json:"development,omitempty"`
116-
SoundName string `json:"name,omitempty"`
117-
SoundVolume float32 `json:"volume,omitempty"`
118-
Apns D `json:"apns,omitempty"`
104+
Expiration *int64 `json:"expiration,omitempty"`
105+
ApnsID string `json:"apns_id,omitempty"`
106+
CollapseID string `json:"collapse_id,omitempty"`
107+
Topic string `json:"topic,omitempty"`
108+
PushType string `json:"push_type,omitempty"`
109+
Badge *int `json:"badge,omitempty"`
110+
Category string `json:"category,omitempty"`
111+
ThreadID string `json:"thread-id,omitempty"`
112+
URLArgs []string `json:"url-args,omitempty"`
113+
Alert Alert `json:"alert,omitempty"`
114+
Production bool `json:"production,omitempty"`
115+
Development bool `json:"development,omitempty"`
116+
SoundName string `json:"name,omitempty"`
117+
SoundVolume float32 `json:"volume,omitempty"`
118+
Apns D `json:"apns,omitempty"`
119+
InterruptionLevel string `json:"interruption_level,omitempty"` // ref: https://github.com/sideshow/apns2/blob/54928d6193dfe300b6b88dad72b7e2ae138d4f0a/payload/builder.go#L7-L24
119120
}
120121

121122
// Bytes for queue message

notify/notification_apns.go

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -217,72 +217,76 @@ func configureHTTP2ConnHealthCheck(h2Transport *http2.Transport) {
217217
h2Transport.PingTimeout = 1 * time.Second
218218
}
219219

220-
func iosAlertDictionary(payload *payload.Payload, req *PushNotification) *payload.Payload {
220+
func iosAlertDictionary(notificationPayload *payload.Payload, req *PushNotification) *payload.Payload {
221221
// Alert dictionary
222222

223223
if len(req.Title) > 0 {
224-
payload.AlertTitle(req.Title)
224+
notificationPayload.AlertTitle(req.Title)
225+
}
226+
227+
if len(req.InterruptionLevel) > 0 {
228+
notificationPayload.InterruptionLevel(payload.EInterruptionLevel(req.InterruptionLevel))
225229
}
226230

227231
if len(req.Message) > 0 && len(req.Title) > 0 {
228-
payload.AlertBody(req.Message)
232+
notificationPayload.AlertBody(req.Message)
229233
}
230234

231235
if len(req.Alert.Title) > 0 {
232-
payload.AlertTitle(req.Alert.Title)
236+
notificationPayload.AlertTitle(req.Alert.Title)
233237
}
234238

235239
// Apple Watch & Safari display this string as part of the notification interface.
236240
if len(req.Alert.Subtitle) > 0 {
237-
payload.AlertSubtitle(req.Alert.Subtitle)
241+
notificationPayload.AlertSubtitle(req.Alert.Subtitle)
238242
}
239243

240244
if len(req.Alert.TitleLocKey) > 0 {
241-
payload.AlertTitleLocKey(req.Alert.TitleLocKey)
245+
notificationPayload.AlertTitleLocKey(req.Alert.TitleLocKey)
242246
}
243247

244248
if len(req.Alert.LocArgs) > 0 {
245-
payload.AlertLocArgs(req.Alert.LocArgs)
249+
notificationPayload.AlertLocArgs(req.Alert.LocArgs)
246250
}
247251

248252
if len(req.Alert.TitleLocArgs) > 0 {
249-
payload.AlertTitleLocArgs(req.Alert.TitleLocArgs)
253+
notificationPayload.AlertTitleLocArgs(req.Alert.TitleLocArgs)
250254
}
251255

252256
if len(req.Alert.Body) > 0 {
253-
payload.AlertBody(req.Alert.Body)
257+
notificationPayload.AlertBody(req.Alert.Body)
254258
}
255259

256260
if len(req.Alert.LaunchImage) > 0 {
257-
payload.AlertLaunchImage(req.Alert.LaunchImage)
261+
notificationPayload.AlertLaunchImage(req.Alert.LaunchImage)
258262
}
259263

260264
if len(req.Alert.LocKey) > 0 {
261-
payload.AlertLocKey(req.Alert.LocKey)
265+
notificationPayload.AlertLocKey(req.Alert.LocKey)
262266
}
263267

264268
if len(req.Alert.Action) > 0 {
265-
payload.AlertAction(req.Alert.Action)
269+
notificationPayload.AlertAction(req.Alert.Action)
266270
}
267271

268272
if len(req.Alert.ActionLocKey) > 0 {
269-
payload.AlertActionLocKey(req.Alert.ActionLocKey)
273+
notificationPayload.AlertActionLocKey(req.Alert.ActionLocKey)
270274
}
271275

272276
// General
273277
if len(req.Category) > 0 {
274-
payload.Category(req.Category)
278+
notificationPayload.Category(req.Category)
275279
}
276280

277281
if len(req.Alert.SummaryArg) > 0 {
278-
payload.AlertSummaryArg(req.Alert.SummaryArg)
282+
notificationPayload.AlertSummaryArg(req.Alert.SummaryArg)
279283
}
280284

281285
if req.Alert.SummaryArgCount > 0 {
282-
payload.AlertSummaryArgCount(req.Alert.SummaryArgCount)
286+
notificationPayload.AlertSummaryArgCount(req.Alert.SummaryArgCount)
283287
}
284288

285-
return payload
289+
return notificationPayload
286290
}
287291

288292
// GetIOSNotification use for define iOS notification.

notify/notification_apns_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ func TestIOSAlertNotificationStructure(t *testing.T) {
526526
TitleLocArgs: []string{"a", "b"},
527527
TitleLocKey: test,
528528
},
529+
InterruptionLevel: test,
529530
}
530531

531532
notification := GetIOSNotification(req)
@@ -546,6 +547,7 @@ func TestIOSAlertNotificationStructure(t *testing.T) {
546547
title, _ := jsonparser.GetString(data, "aps", "alert", "title")
547548
subtitle, _ := jsonparser.GetString(data, "aps", "alert", "subtitle")
548549
titleLocKey, _ := jsonparser.GetString(data, "aps", "alert", "title-loc-key")
550+
interruptionLevel, _ := jsonparser.GetString(data, "aps", "interruption-level")
549551
aps := dat["aps"].(map[string]interface{})
550552
alert := aps["alert"].(map[string]interface{})
551553
titleLocArgs := alert["title-loc-args"].([]interface{})
@@ -559,6 +561,7 @@ func TestIOSAlertNotificationStructure(t *testing.T) {
559561
assert.Equal(t, test, title)
560562
assert.Equal(t, test, subtitle)
561563
assert.Equal(t, test, titleLocKey)
564+
assert.Equal(t, test, interruptionLevel)
562565
assert.Contains(t, titleLocArgs, "a")
563566
assert.Contains(t, titleLocArgs, "b")
564567
assert.Contains(t, locArgs, "a")

0 commit comments

Comments
 (0)