diff --git a/gorush/notification.go b/gorush/notification.go index 821965b..7169f56 100644 --- a/gorush/notification.go +++ b/gorush/notification.go @@ -304,7 +304,8 @@ func GetIOSNotification(req PushNotification) *apns.Notification { payload := payload.NewPayload().Alert(req.Message) - if req.Badge > 0 { + // zero value for clear the badge on the app icon. + if req.Badge >= 0 { payload.Badge(req.Badge) } diff --git a/gorush/notification_test.go b/gorush/notification_test.go index 9c4524f..efb2662 100644 --- a/gorush/notification_test.go +++ b/gorush/notification_test.go @@ -72,7 +72,7 @@ func TestIOSNotificationStructure(t *testing.T) { Expiration: time.Now().Unix(), Priority: "normal", Message: message, - Badge: 1, + Badge: 0, Sound: test, ContentAvailable: true, Data: D{ @@ -108,7 +108,7 @@ func TestIOSNotificationStructure(t *testing.T) { assert.Equal(t, unix, notification.Expiration.Unix()) assert.Equal(t, ApnsPriorityLow, notification.Priority) assert.Equal(t, message, alert) - assert.Equal(t, 1, int(badge)) + assert.Equal(t, 0, int(badge)) assert.Equal(t, test, sound) assert.Equal(t, 1, int(contentAvailable)) assert.Equal(t, "test", key1)