Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
ringsaturn committed May 10, 2023
1 parent 3bb6070 commit 835d550
Showing 1 changed file with 57 additions and 26 deletions.
83 changes: 57 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# APNS/2

APNS/2 is a go package designed for simple, flexible and fast Apple Push Notifications on iOS, OSX and Safari using the new HTTP/2 Push provider API.
APNS/2 is a go package designed for simple, flexible and fast Apple Push
Notifications on iOS, OSX and Safari using the new HTTP/2 Push provider API.

[![Build Status](https://github.com/sideshow/apns2/actions/workflows/tests.yml/badge.svg)](https://github.com/sideshow/apns2/actions/workflows/tests.yml) [![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)
[![Build Status](https://github.com/sideshow/apns2/actions/workflows/tests.yml/badge.svg)](https://github.com/sideshow/apns2/actions/workflows/tests.yml)
[![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)

## Features

- Uses new Apple APNs HTTP/2 connection
- Fast - See [notes on speed](https://github.com/sideshow/apns2/wiki/APNS-HTTP-2-Push-Speed)
- Works with go 1.7 and later
- Fast - See
[notes on speed](https://github.com/sideshow/apns2/wiki/APNS-HTTP-2-Push-Speed)
- Works with go 1.19 and later
- Supports new Apple Token Based Authentication (JWT)
- Supports new iOS 10 features such as Collapse IDs, Subtitles and Mutable Notifications
- Supports new iOS 10 features such as Collapse IDs, Subtitles and Mutable
Notifications
- Supports new iOS 15 features interruptionLevel and relevanceScore
- Supports persistent connections to APNs
- Supports VoIP/PushKit notifications (iOS 8 and later)
Expand All @@ -19,18 +24,18 @@ APNS/2 is a go package designed for simple, flexible and fast Apple Push Notific

## Install

- Make sure you have [Go](https://golang.org/doc/install) installed and have set your [GOPATH](https://golang.org/doc/code.html#GOPATH).
- Install apns2:
- Make sure you have [Go](https://golang.org/doc/install) installed and have set
your [GOPATH](https://golang.org/doc/code.html#GOPATH).
- Install apns2: It's recommended to use `replace` to keep using sideshow's
upstream repo in your `go.mod`:

```sh
go get -u github.com/sideshow/apns2
```

If you are running the test suite you will also need to install testify:
```
require (
github.com/sideshow/apns2 v0.23.0
)
```sh
go get -u github.com/stretchr/testify
```
replace github.com/sideshow/apns2 => github.com/ringsaturn/apns2 v0.24.0
```

## Example

Expand Down Expand Up @@ -75,7 +80,10 @@ func main() {
## JWT Token Example

Instead of using a `.p12` or `.pem` certificate as above, you can optionally use
APNs JWT _Provider Authentication Tokens_. First you will need a signing key (`.p8` file), Key ID and Team ID [from Apple](http://help.apple.com/xcode/mac/current/#/dev54d690a66). Once you have these details, you can create a new client:
APNs JWT _Provider Authentication Tokens_. First you will need a signing key
(`.p8` file), Key ID and Team ID
[from Apple](http://help.apple.com/xcode/mac/current/#/dev54d690a66). Once you
have these details, you can create a new client:

```go
authKey, err := token.AuthKeyFromFile("../AuthKey_XXX.p8")
Expand Down Expand Up @@ -122,7 +130,8 @@ notification.Priority = apns2.PriorityLow

## Payload

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.
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.

```go
// {"aps":{"alert":"hello","badge":1},"key":"val"}
Expand All @@ -133,14 +142,22 @@ notification.Payload = payload
client.Push(notification)
```

Refer to the [payload](https://godoc.org/github.com/sideshow/apns2/payload) docs for more info.
Refer to the [payload](https://godoc.org/github.com/sideshow/apns2/payload) docs
for more info.

## Response, Error handling

APNS/2 draws the distinction between a valid response from Apple indicating whether or not the _Notification_ was sent or not, and an unrecoverable or unexpected _Error_;
APNS/2 draws the distinction between a valid response from Apple indicating
whether or not the _Notification_ was sent or not, and an unrecoverable or
unexpected _Error_;

- 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.
- 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.
- 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.
- 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.

To check if a `Notification` was successfully sent;

Expand Down Expand Up @@ -174,17 +191,31 @@ defer cancel()

## Speed & Performance

Also see the wiki page on [APNS HTTP 2 Push Speed](https://github.com/sideshow/apns2/wiki/APNS-HTTP-2-Push-Speed).
Also see the wiki page on
[APNS HTTP 2 Push Speed](https://github.com/sideshow/apns2/wiki/APNS-HTTP-2-Push-Speed).

For best performance, you should hold on to an `apns2.Client` instance and not re-create it every push. The underlying TLS connection itself can take a few seconds to connect and negotiate, so if you are setting up an `apns2.Client` and tearing it down every push, then this will greatly affect performance. (Apple suggest keeping the connection open all the time).
For best performance, you should hold on to an `apns2.Client` instance and not
re-create it every push. The underlying TLS connection itself can take a few
seconds to connect and negotiate, so if you are setting up an `apns2.Client` and
tearing it down every push, then this will greatly affect performance. (Apple
suggest keeping the connection open all the time).

You should also limit the amount of `apns2.Client` instances. The underlying transport has a http connection pool itself, so a single client instance will be enough for most users (One instance can potentially do 4,000+ pushes per second). If you need more than this then one instance per CPU core is a good starting point.
You should also limit the amount of `apns2.Client` instances. The underlying
transport has a http connection pool itself, so a single client instance will be
enough for most users (One instance can potentially do 4,000+ pushes per
second). If you need more than this then one instance per CPU core is a good
starting point.

Speed is greatly affected by the location of your server and the quality of your network connection. If you're just testing locally, behind a proxy or if your server is outside USA then you're not going to get great performance. With a good server located in AWS, you should be able to get [decent throughput](https://github.com/sideshow/apns2/wiki/APNS-HTTP-2-Push-Speed).
Speed is greatly affected by the location of your server and the quality of your
network connection. If you're just testing locally, behind a proxy or if your
server is outside USA then you're not going to get great performance. With a
good server located in AWS, you should be able to get
[decent throughput](https://github.com/sideshow/apns2/wiki/APNS-HTTP-2-Push-Speed).

## Command line tool

APNS/2 has a command line tool that can be installed with `go get github.com/sideshow/apns2/apns2`. Usage:
APNS/2 has a command line tool that can be installed with
`go install github.com/ringsaturn/apns2/apns2`. Usage:

```
apns2 --help
Expand Down

0 comments on commit 835d550

Please sign in to comment.