From 1c82f5c90456bb031857a1f06368e1d0eb5be5a4 Mon Sep 17 00:00:00 2001 From: Emmet McPoland Date: Mon, 23 Sep 2019 16:36:38 +0100 Subject: [PATCH] Added support for iOS13 with apns-push-type (#424) --- README.md | 1 + go.mod | 2 +- gorush/notification.go | 1 + gorush/notification_apns.go | 4 ++++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a0ac3b1..18c7b59 100644 --- a/README.md +++ b/README.md @@ -538,6 +538,7 @@ Request body must has a notifications array. The following is a parameter table | notification | string array | payload of a FCM message | - | only Android. See the [detail](#android-notification-payload) | | expiration | int | expiration for notification | - | only iOS | | apns_id | string | A canonical UUID that identifies the notification | - | only iOS | +| push_type | string | The type of the notification. The value of this header is alert or background. | - | only iOS | | badge | int | badge count | - | only iOS | | category | string | the UIMutableUserNotificationCategory object | - | only iOS | | alert | string array | payload of a iOS message | - | only iOS. See the [detail](#ios-alert-payload) | diff --git a/go.mod b/go.mod index c268178..2b55a85 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/mattn/go-isatty v0.0.8 github.com/mitchellh/mapstructure v1.1.2 github.com/prometheus/client_golang v1.0.0 - github.com/sideshow/apns2 v0.16.0 + github.com/sideshow/apns2 v0.19.0 github.com/sirupsen/logrus v1.4.2 github.com/spf13/viper v1.4.0 github.com/stretchr/testify v1.3.0 diff --git a/gorush/notification.go b/gorush/notification.go index 1734661..fe920df 100644 --- a/gorush/notification.go +++ b/gorush/notification.go @@ -82,6 +82,7 @@ type PushNotification struct { ApnsID string `json:"apns_id,omitempty"` CollapseID string `json:"collapse_id,omitempty"` Topic string `json:"topic,omitempty"` + PushType string `json:"push_type,omitempty"` Badge *int `json:"badge,omitempty"` Category string `json:"category,omitempty"` ThreadID string `json:"thread-id,omitempty"` diff --git a/gorush/notification_apns.go b/gorush/notification_apns.go index 76a8170..61060ab 100644 --- a/gorush/notification_apns.go +++ b/gorush/notification_apns.go @@ -183,6 +183,10 @@ func GetIOSNotification(req PushNotification) *apns2.Notification { notification.Priority = apns2.PriorityLow } + if len(req.PushType) > 0 { + notification.PushType = apns2.EPushType(req.PushType) + } + payload := payload.NewPayload() // add alert object if message length > 0