Skip to content

Commit

Permalink
Add APNS Push Type
Browse files Browse the repository at this point in the history
  • Loading branch information
kitefaster committed Jun 17, 2019
1 parent d5157a5 commit 4eb5e21
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
3 changes: 3 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,7 @@ func setHeaders(r *http.Request, n *Notification) {
if !n.Expiration.IsZero() {
r.Header.Set("apns-expiration", fmt.Sprintf("%v", n.Expiration.Unix()))
}
if n.PushType != "" {
r.Header.Set("apns-push-type", string(n.PushType))
}
}
22 changes: 19 additions & 3 deletions notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,25 @@ import (
"time"
)

type Priority int
const (
// PriorityLow will tell APNs to send the push message at a time that takes
// into account power considerations for the device. Notifications with this
// priority might be grouped and delivered in bursts. They are throttled, and
// in some cases are not delivered.
PriorityLow = 5
PriorityLow Priority = 5

// PriorityHigh will tell APNs to send the push message immediately.
// Notifications with this priority must trigger an alert, sound, or badge on
// the target device. It is an error to use this priority for a push
// notification that contains only the content-available key.
PriorityHigh = 10
PriorityHigh Priority = 10
)

type ApnsPushType string
const (
ApnsPushTypeAlert ApnsPushType = "alert"
ApnsPushTypeBackground ApnsPushType = "background"
)

// Notification represents the the data and metadata for a APNs Remote Notification.
Expand Down Expand Up @@ -59,7 +66,16 @@ type Notification struct {
// The priority of the notification. Specify ether apns.PriorityHigh (10) or
// apns.PriorityLow (5) If you don't set this, the APNs server will set the
// priority to 10.
Priority int
Priority Priority

// (Required when delivering notifications to devices running iOS 13 and later, or watchOS 6 and later.
// Ignored on earlier system versions.) The type of the notification.
// The value of this header is alert or background. Specify alert when the delivery of your notification displays an alert,
// plays a sound, or badges your app's icon. Specify background for silent notifications that do not interact with the user.
// The value of this header must accurately reflect the contents of your notification's payload.
// If there is a mismatch, or if the header is missing on required systems,
// APNs may delay the delivery of the notification or drop it altogether.
PushType ApnsPushType

// A byte array containing the JSON-encoded payload of this push notification.
// Refer to "The Remote Notification Payload" section in the Apple Local and
Expand Down

0 comments on commit 4eb5e21

Please sign in to comment.