Add CollapseID for ios notification. (#308)

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2017-11-15 10:12:09 -06:00 committed by GitHub
parent b7b9cd22dd
commit bd6a6f7eba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 2 deletions

View File

@ -76,6 +76,7 @@ type PushNotification struct {
// iOS // iOS
Expiration int64 `json:"expiration,omitempty"` Expiration int64 `json:"expiration,omitempty"`
ApnsID string `json:"apns_id,omitempty"` ApnsID string `json:"apns_id,omitempty"`
CollapseID string `json:"collapse_id,omitempty"`
Topic string `json:"topic,omitempty"` Topic string `json:"topic,omitempty"`
Badge *int `json:"badge,omitempty"` Badge *int `json:"badge,omitempty"`
Category string `json:"category,omitempty"` Category string `json:"category,omitempty"`

View File

@ -127,6 +127,7 @@ func GetIOSNotification(req PushNotification) *apns2.Notification {
notification := &apns2.Notification{ notification := &apns2.Notification{
ApnsID: req.ApnsID, ApnsID: req.ApnsID,
Topic: req.Topic, Topic: req.Topic,
CollapseID: req.CollapseID,
} }
if req.Expiration > 0 { if req.Expiration > 0 {

View File

@ -180,6 +180,7 @@ func TestCheckSilentNotification(t *testing.T) {
req := PushNotification{ req := PushNotification{
ApnsID: test, ApnsID: test,
Topic: test, Topic: test,
CollapseID: test,
Priority: "normal", Priority: "normal",
ContentAvailable: true, ContentAvailable: true,
} }
@ -194,6 +195,9 @@ func TestCheckSilentNotification(t *testing.T) {
panic(err) panic(err)
} }
assert.Equal(t, test, notification.CollapseID)
assert.Equal(t, test, notification.ApnsID)
assert.Equal(t, test, notification.Topic)
assert.Nil(t, dat["aps"].(map[string]interface{})["alert"]) assert.Nil(t, dat["aps"].(map[string]interface{})["alert"])
assert.Nil(t, dat["aps"].(map[string]interface{})["sound"]) assert.Nil(t, dat["aps"].(map[string]interface{})["sound"])
assert.Nil(t, dat["aps"].(map[string]interface{})["badge"]) assert.Nil(t, dat["aps"].(map[string]interface{})["badge"])