feat: Add support for the mutable-content flag (#179)

This commit is contained in:
Bo-Yi Wu 2017-02-10 15:03:49 +08:00 committed by GitHub
parent ef9085c4b7
commit 3f4485edf7
3 changed files with 16 additions and 7 deletions

View File

@ -415,6 +415,7 @@ Request body must has a notifications array. The following is a parameter table
| 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) |
| mutable_content | bool | enable Notification Service app extension. | - | only iOS(10.0+).
### iOS alert payload

View File

@ -81,6 +81,7 @@ type PushNotification struct {
Category string `json:"category,omitempty"`
URLArgs []string `json:"url-args,omitempty"`
Alert Alert `json:"alert,omitempty"`
MutableContent bool `json:"mutable-content,omitempty"`
}
// CheckMessage for check request message
@ -314,6 +315,10 @@ func GetIOSNotification(req PushNotification) *apns.Notification {
payload.Badge(*req.Badge)
}
if req.MutableContent {
payload.MutableContent()
}
if len(req.Sound) > 0 {
payload.Sound(req.Sound)
}

View File

@ -135,6 +135,7 @@ func TestSendZeroValueForBadgeKey(t *testing.T) {
Message: message,
Sound: test,
ContentAvailable: true,
MutableContent: true,
}
notification := GetIOSNotification(req)
@ -151,6 +152,7 @@ func TestSendZeroValueForBadgeKey(t *testing.T) {
badge, _ := jsonparser.GetInt(data, "aps", "badge")
sound, _ := jsonparser.GetString(data, "aps", "sound")
contentAvailable, _ := jsonparser.GetInt(data, "aps", "content-available")
mutableContent, _ := jsonparser.GetInt(data, "aps", "mutable-content")
if req.Badge != nil {
t.Errorf("req.Badge must be nil")
@ -163,6 +165,7 @@ func TestSendZeroValueForBadgeKey(t *testing.T) {
assert.Equal(t, 0, int(badge))
assert.Equal(t, test, sound)
assert.Equal(t, 1, int(contentAvailable))
assert.Equal(t, 1, int(mutableContent))
// Add Bage
expectBadge := 10