Skip to content
This repository was archived by the owner on Jun 6, 2023. It is now read-only.

Commit

Permalink
add collapse id for notification management (#68)
Browse files Browse the repository at this point in the history
ref #62
  • Loading branch information
nathany authored Jun 16, 2016
1 parent 259170c commit 07abe3c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions push/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ type Headers struct {
// This should be a UUID with 32 lowercase hexadecimal digits.
ID string

// CollapseID is used to update an existing notification that has the same
// identifier (Notification Management in iOS 10).
CollapseID string

// Apple will retry delivery until this time. The default behavior only tries once.
Expiration time.Time

Expand All @@ -34,6 +38,10 @@ func (h *Headers) set(reqHeader http.Header) {
reqHeader.Set("apns-id", h.ID)
} // when omitted, Apple will generate a UUID for you

if h.CollapseID != "" {
reqHeader.Set("apns-collapse-id", h.CollapseID)
}

if !h.Expiration.IsZero() {
reqHeader.Set("apns-expiration", strconv.FormatInt(h.Expiration.Unix(), 10))
}
Expand Down
4 changes: 4 additions & 0 deletions push/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
func TestHeaders(t *testing.T) {
headers := Headers{
ID: "uuid",
CollapseID: "game1.score.identifier",
Expiration: time.Unix(12622780800, 0),
LowPriority: true,
Topic: "bundle-id",
Expand All @@ -18,6 +19,7 @@ func TestHeaders(t *testing.T) {
headers.set(reqHeader)

testHeader(t, reqHeader, "apns-id", "uuid")
testHeader(t, reqHeader, "apns-collapse-id", "game1.score.identifier")
testHeader(t, reqHeader, "apns-expiration", "12622780800")
testHeader(t, reqHeader, "apns-priority", "5")
testHeader(t, reqHeader, "apns-topic", "bundle-id")
Expand All @@ -29,6 +31,7 @@ func TestNilHeader(t *testing.T) {
headers.set(reqHeader)

testHeader(t, reqHeader, "apns-id", "")
testHeader(t, reqHeader, "apns-collapse-id", "")
testHeader(t, reqHeader, "apns-expiration", "")
testHeader(t, reqHeader, "apns-priority", "")
testHeader(t, reqHeader, "apns-topic", "")
Expand All @@ -40,6 +43,7 @@ func TestEmptyHeaders(t *testing.T) {
headers.set(reqHeader)

testHeader(t, reqHeader, "apns-id", "")
testHeader(t, reqHeader, "apns-collapse-id", "")
testHeader(t, reqHeader, "apns-expiration", "")
testHeader(t, reqHeader, "apns-priority", "")
testHeader(t, reqHeader, "apns-topic", "")
Expand Down

0 comments on commit 07abe3c

Please sign in to comment.