Skip to content

arashpayan/apns

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

This project is no longer maintained. Check out anachronistic/apns instead.

Introduction

This Go package provides a client that can establish a connection with the Apple Push Notification service and deliver notifications to end users based on a device token. This package has been implemented according to Apple's documentation (available at ever changing/breaking URLs).

GoDoc

Installation

go get github.com/arashpayan/apns

Usage

Create a Client and connect to the APNs

client := apns.NewClient(apns.SandboxGateway, // or apns.ProductionGateway
    "/path/to/my/signed/cert/file.crt",
    "/path/to/my/private/key/file.key",
    func(invalidToken string) {
        // called when we try to send a notification to an invalid token
        // You should delete the token from your db by disassociating it with
        // the user you tried sending the notification too. When this is called
        // it means the person either uninstalled your app or has switched to
        // a new device.
    })
err := client.Connect()
if err != nil {
    // handle the connection error
}

Create a Notification

n := apns.NewNotification(aDeviceToken)
n.Alert = "Hello, user!"
n.Badge = 1
// optionally, include app data ('aps' element of notification json)
n.AppData = map[string]interface{}{"sound":"tada", "Foo":"Bar"}

Send the Notification

client.Send(n)

About

Go library to send messages through the Apple Push Notification service (APNs)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages