Skip to content

Commit

Permalink
Add ApnsUniqueID identifier for development push
Browse files Browse the repository at this point in the history
  • Loading branch information
sideshow committed Aug 11, 2024
1 parent 09b8370 commit dbe5af3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ func (c *Client) PushWithContext(ctx Context, n *Notification) (*Response, error
r := &Response{}
r.StatusCode = response.StatusCode
r.ApnsID = response.Header.Get("apns-id")
r.ApnsUniqueID = response.Header.Get("apns-unique-id")

decoder := json.NewDecoder(response.Body)
if err := decoder.Decode(r); err != nil && err != io.EOF {
Expand Down Expand Up @@ -234,5 +235,4 @@ func setHeaders(r *http.Request, n *Notification) {
} else {
r.Header.Set("apns-push-type", string(PushTypeAlert))
}

}
3 changes: 3 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,16 +370,19 @@ func TestBadPayload(t *testing.T) {
func Test200SuccessResponse(t *testing.T) {
n := mockNotification()
var apnsID = "02ABC856-EF8D-4E49-8F15-7B8A61D978D6"
var apnsUniqueID = "A6739D99-D92A-424B-A91E-BF012365BD4E"
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Header().Set("apns-id", apnsID)
w.Header().Set("apns-unique-id", apnsUniqueID)
w.WriteHeader(http.StatusOK)
}))
defer server.Close()
res, err := mockClient(server.URL).Push(n)
assert.NoError(t, err)
assert.Equal(t, http.StatusOK, res.StatusCode)
assert.Equal(t, apnsID, res.ApnsID)
assert.Equal(t, apnsUniqueID, res.ApnsUniqueID)
assert.Equal(t, true, res.Sent())
}

Expand Down
5 changes: 5 additions & 0 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ type Response struct {
// If the value of StatusCode is 410, this is the last time at which APNs
// confirmed that the device token was no longer valid for the topic.
Timestamp Time

// An identifier that is only available in the Developement enviroment. Use
// this to query Delivery Log information for the corresponding notification
// in Push Notifications Console.
ApnsUniqueID string
}

// Sent returns whether or not the notification was successfully sent.
Expand Down

0 comments on commit dbe5af3

Please sign in to comment.