Skip to content

Commit ea0160c

Browse files
committed
Add reference to payload package
1 parent 5eb61e9 commit ea0160c

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ APNS/2 is a go package designed for simple, flexible and fast Apple Push Notific
55
[![Build Status](https://travis-ci.org/sideshow/apns2.svg?branch=master)](https://travis-ci.org/sideshow/apns2) [![Coverage Status](https://coveralls.io/repos/sideshow/apns2/badge.svg?branch=master&service=github)](https://coveralls.io/github/sideshow/apns2?branch=master) [![GoDoc](https://godoc.org/github.com/sideshow/apns2?status.svg)](https://godoc.org/github.com/sideshow/apns2)
66

77
## Features
8+
89
- Uses new Apple APNs HTTP/2 connection
910
- Works with older versions of go (1.4.x) not just 1.6
1011
- Supports persistent connections to APNs
1112
- Fast, modular & easy to use
1213
- Tested and working in APNs production environment
1314

1415
## Install
16+
1517
1. `go get -u golang.org/x/net/http2` (Support for HTTP/2 until go1.6 is out of beta)
1618
2. `go get -u golang.org/x/crypto/pkcs12`
1719

@@ -36,7 +38,7 @@ func main() {
3638
notification := &apns.Notification{}
3739
notification.DeviceToken = "11aa01229f15f0f0c52029d8cf8cd0aeaf2365fe4cebc4af26cd6d76b7919ef7"
3840
notification.Topic = "com.sideshow.Apns2"
39-
notification.Payload = []byte(`{"aps":{"alert":"Hello!"}}`)
41+
notification.Payload = []byte(`{"aps":{"alert":"Hello!"}}`) // See Payload section below
4042

4143
client := apns.NewClient(cert).Development()
4244
res, err := client.Push(notification)
@@ -49,6 +51,7 @@ func main() {
4951
```
5052

5153
## Notification
54+
5255
At a minimum, a _Notification_ needs a _DeviceToken_, a _Topic_ and a _Payload_.
5356

5457
```go
@@ -67,8 +70,25 @@ notification.Expiration = time.Now()
6770
notification.Priority = apns.PriorityLow
6871
```
6972

73+
## Payload
74+
75+
You can use raw bytes for the `notification.Payload` as above, or you can use the payload builder package which makes it easy to construct APNs payloads.
76+
77+
```go
78+
// {"aps":{"alert":"hello","badge":1},"key":"val"}
79+
80+
payload := NewPayload().Alert("hello").Badge(1).Custom("key", "val")
81+
82+
notification.Payload = payload
83+
client.Push(notification)
84+
```
85+
86+
Refer to the [payload](https://godoc.org/github.com/sideshow/apns2/payload) docs for more info.
87+
7088
## Response, Error handling
89+
7190
APNS/2 draws the distinction between a valid response from Apple indicating wether or not the _Notification_ was sent or not, and an unrecoverable or unexpected _Error_;
91+
7292
- An `Error` is returned if a non-recoverable error occurs, i.e. if there is a problem with the underlying _http.Client_ connection or _Certificate_, the payload was not sent, or a valid _Response_ was not received.
7393
- A `Response` is returned if the payload was successfully sent to Apple and a documented response was received. This struct will contain more information about whether or not the push notification succeeded, its _apns-id_ and if applicable, more information around why it did not succeed.
7494

@@ -107,6 +127,7 @@ Flags:
107127
```
108128

109129
## License
130+
110131
The MIT License (MIT)
111132

112133
Copyright (c) 2016 Adam Jones

0 commit comments

Comments
 (0)