This Go package implements the Apple Push Notification System (APNs) binary interface.
This package provides simple interfaces for establishing authenticated
connections to APNs gateways and sending notifications. The function
apns.DialAPN(...)
returns a net.Conn
which is authenticated and ready to
receive data. Notifications implement the io.Writer
and io.Reader
interfaces so that sending a notification is done by having it write to a
connection.
var notif = `
{
"command": 2,
"device-token": "beefca5e",
"identifier": 1,
"expiry": 0,
"priority": 10,
"payload": {
"aps" : {
"content-available": 1,
"alert" : "Hello World",
"badge" : 42
}
}
}`
func main() {
cert, _ := apns.LoadPemFile("notifyme_cert.pem") // Load the pem file from the current dir.
conn, _ := apns.DialAPN(&cert, apns.SANDBOX, false)
defer conn.Close()
n := apns.MakeNotification([]byte(notif))
n.WriteTo(conn)
}
Other Go implementations of APNs:
Other non-Go APNs projects:
The apnsend utility is a command line tool which uses the apns package for sending push notifications.
[note: this is probably broken right now] The apnserver utility will respond to the APNs protocol with mock data. The server can be configured to a specific mock failure rate to simulate errors and dropped connections.
Distribution and use of this project is governed by the [3-clause] Revised BSD license that can be found in the LICENSE file.