ignore alert object if message is empty.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
20c8340875
commit
65d486b65b
|
@ -302,7 +302,12 @@ func GetIOSNotification(req PushNotification) *apns.Notification {
|
||||||
notification.Priority = apns.PriorityLow
|
notification.Priority = apns.PriorityLow
|
||||||
}
|
}
|
||||||
|
|
||||||
payload := payload.NewPayload().Alert(req.Message)
|
payload := payload.NewPayload()
|
||||||
|
|
||||||
|
// add alert object if message length > 0
|
||||||
|
if len(req.Message) > 0 {
|
||||||
|
payload.Alert(req.Message)
|
||||||
|
}
|
||||||
|
|
||||||
// zero value for clear the badge on the app icon.
|
// zero value for clear the badge on the app icon.
|
||||||
if req.Badge != nil && *req.Badge >= 0 {
|
if req.Badge != nil && *req.Badge >= 0 {
|
||||||
|
|
|
@ -186,6 +186,36 @@ func TestSendZeroValueForBadgeKey(t *testing.T) {
|
||||||
assert.Equal(t, expectBadge, int(badge))
|
assert.Equal(t, expectBadge, int(badge))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Silent Notification:
|
||||||
|
// The payload’s aps dictionary must include the content-available key with a value of 1.
|
||||||
|
// The payload’s aps dictionary must not contain the alert, sound, or badge keys.
|
||||||
|
// ref: https://goo.gl/m9xyqG
|
||||||
|
func TestCheckSilentNotification(t *testing.T) {
|
||||||
|
var dat map[string]interface{}
|
||||||
|
|
||||||
|
test := "test"
|
||||||
|
req := PushNotification{
|
||||||
|
ApnsID: test,
|
||||||
|
Topic: test,
|
||||||
|
Priority: "normal",
|
||||||
|
ContentAvailable: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
notification := GetIOSNotification(req)
|
||||||
|
|
||||||
|
dump, _ := json.Marshal(notification.Payload)
|
||||||
|
data := []byte(string(dump))
|
||||||
|
|
||||||
|
if err := json.Unmarshal(data, &dat); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
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{})["badge"])
|
||||||
|
}
|
||||||
|
|
||||||
func TestIOSAlertNotificationStructure(t *testing.T) {
|
func TestIOSAlertNotificationStructure(t *testing.T) {
|
||||||
var dat map[string]interface{}
|
var dat map[string]interface{}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue