feat(ios12): Add support for Summary arguments in notifications (#384)
* feat(ios12): Add support for Summary arguments in notifications * feat: upgrade go module
This commit is contained in:
@@ -30,16 +30,18 @@ const (
|
||||
|
||||
// Alert is APNs payload
|
||||
type Alert struct {
|
||||
Action string `json:"action,omitempty"`
|
||||
ActionLocKey string `json:"action-loc-key,omitempty"`
|
||||
Body string `json:"body,omitempty"`
|
||||
LaunchImage string `json:"launch-image,omitempty"`
|
||||
LocArgs []string `json:"loc-args,omitempty"`
|
||||
LocKey string `json:"loc-key,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
Subtitle string `json:"subtitle,omitempty"`
|
||||
TitleLocArgs []string `json:"title-loc-args,omitempty"`
|
||||
TitleLocKey string `json:"title-loc-key,omitempty"`
|
||||
Action string `json:"action,omitempty"`
|
||||
ActionLocKey string `json:"action-loc-key,omitempty"`
|
||||
Body string `json:"body,omitempty"`
|
||||
LaunchImage string `json:"launch-image,omitempty"`
|
||||
LocArgs []string `json:"loc-args,omitempty"`
|
||||
LocKey string `json:"loc-key,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
Subtitle string `json:"subtitle,omitempty"`
|
||||
TitleLocArgs []string `json:"title-loc-args,omitempty"`
|
||||
TitleLocKey string `json:"title-loc-key,omitempty"`
|
||||
SummaryArg string `json:"summary-arg,omitempty"`
|
||||
SummaryArgCount int `json:"summary-arg-count,omitempty"`
|
||||
}
|
||||
|
||||
// RequestPush support multiple notification request.
|
||||
|
||||
@@ -148,11 +148,18 @@ func iosAlertDictionary(payload *payload.Payload, req PushNotification) *payload
|
||||
}
|
||||
|
||||
// General
|
||||
|
||||
if len(req.Category) > 0 {
|
||||
payload.Category(req.Category)
|
||||
}
|
||||
|
||||
if len(req.Alert.SummaryArg) > 0 {
|
||||
payload.AlertSummaryArg(req.Alert.SummaryArg)
|
||||
}
|
||||
|
||||
if req.Alert.SummaryArgCount > 0 {
|
||||
payload.AlertSummaryArgCount(req.Alert.SummaryArgCount)
|
||||
}
|
||||
|
||||
return payload
|
||||
}
|
||||
|
||||
|
||||
@@ -157,6 +157,38 @@ func TestIOSSoundAndVolume(t *testing.T) {
|
||||
assert.Equal(t, int64(1), soundCritical)
|
||||
}
|
||||
|
||||
func TestIOSSummaryArg(t *testing.T) {
|
||||
var dat map[string]interface{}
|
||||
|
||||
test := "test"
|
||||
message := "Welcome notification Server"
|
||||
req := PushNotification{
|
||||
ApnsID: test,
|
||||
Topic: test,
|
||||
Priority: "normal",
|
||||
Message: message,
|
||||
Alert: Alert{
|
||||
SummaryArg: "test",
|
||||
SummaryArgCount: 3,
|
||||
},
|
||||
}
|
||||
|
||||
notification := GetIOSNotification(req)
|
||||
|
||||
dump, _ := json.Marshal(notification.Payload)
|
||||
data := []byte(string(dump))
|
||||
|
||||
if err := json.Unmarshal(data, &dat); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, test, notification.ApnsID)
|
||||
assert.Equal(t, test, notification.Topic)
|
||||
assert.Equal(t, ApnsPriorityLow, notification.Priority)
|
||||
assert.Equal(t, "test", dat["aps"].(map[string]interface{})["alert"].(map[string]interface{})["summary-arg"])
|
||||
assert.Equal(t, float64(3), dat["aps"].(map[string]interface{})["alert"].(map[string]interface{})["summary-arg-count"])
|
||||
}
|
||||
|
||||
// Silent Notification which payload’s aps dictionary must not contain the alert, sound, or badge keys.
|
||||
// ref: https://goo.gl/m9xyqG
|
||||
func TestSendZeroValueForBadgeKey(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user