Skip to content

Commit 88a36b9

Browse files
wiggissersideshow
authored andcommitted
Add support for the apns-push-type header (#139)
* add support for the apns-push-type header
1 parent e5c68d5 commit 88a36b9

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

client.go

+6
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,10 @@ func setHeaders(r *http.Request, n *Notification) {
208208
if !n.Expiration.IsZero() {
209209
r.Header.Set("apns-expiration", fmt.Sprintf("%v", n.Expiration.Unix()))
210210
}
211+
if n.PushType != "" {
212+
r.Header.Set("apns-push-type", string(n.PushType))
213+
} else {
214+
r.Header.Set("apns-push-type", string(PushTypeAlert))
215+
}
216+
211217
}

client_test.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import (
1616

1717
"golang.org/x/net/http2"
1818

19-
apns "github.com/sideshow/apns2"
2019
"github.com/sideshow/apns2/certificate"
2120
"github.com/sideshow/apns2/token"
2221
"github.com/stretchr/testify/assert"
22+
apns "github.com/sideshow/apns2"
2323
)
2424

2525
// Mocks
@@ -157,6 +157,7 @@ func TestDefaultHeaders(t *testing.T) {
157157
assert.Equal(t, "", r.Header.Get("apns-topic"))
158158
assert.Equal(t, "", r.Header.Get("apns-expiration"))
159159
assert.Equal(t, "", r.Header.Get("thread-id"))
160+
assert.Equal(t, "alert", r.Header.Get("apns-push-type"))
160161
}))
161162
defer server.Close()
162163
_, err := mockClient(server.URL).Push(n)
@@ -176,6 +177,11 @@ func TestHeaders(t *testing.T) {
176177
assert.Equal(t, "10", r.Header.Get("apns-priority"))
177178
assert.Equal(t, n.Topic, r.Header.Get("apns-topic"))
178179
assert.Equal(t, fmt.Sprintf("%v", n.Expiration.Unix()), r.Header.Get("apns-expiration"))
180+
if n.PushType == "" {
181+
assert.Equal(t, "alert", r.Header.Get("apns-push-type"))
182+
} else {
183+
assert.Equal(t, n.PushType, r.Header.Get("apns-push-type"))
184+
}
179185
}))
180186
defer server.Close()
181187
_, err := mockClient(server.URL).Push(n)

notification.go

+14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ import (
55
"time"
66
)
77

8+
//EPushType defines the value for the apns-push-type header
9+
type EPushType string
10+
11+
const (
12+
//PushTypeAlert will set the apns-push-type header to 'alert'
13+
PushTypeAlert EPushType = "alert"
14+
//PushTypeBackground will set the apns-push-type header to 'background'
15+
PushTypeBackground EPushType = "background"
16+
)
17+
818
const (
919
// PriorityLow will tell APNs to send the push message at a time that takes
1020
// into account power considerations for the device. Notifications with this
@@ -65,6 +75,10 @@ type Notification struct {
6575
// Refer to "The Remote Notification Payload" section in the Apple Local and
6676
// Remote Notification Programming Guide for more info.
6777
Payload interface{}
78+
79+
// The pushtype of the push notification. If this values is left as the default
80+
// an apns-push-type header with value 'alert' will be added to the http request.
81+
PushType EPushType
6882
}
6983

7084
// MarshalJSON converts the notification payload to JSON.

0 commit comments

Comments
 (0)