Skip to content

npaton/goapn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

apn is a Go Apple Push Notification package. Heavily uses queues and goroutines. 
It has a few tests and seems to work properly but it hasn't had thorough testing and hasn't gone into production yet. 
Feedback service not supported yet. [3]

NB: This is my first Go code ever.

Installation

        goinstall github.com/nicolaspaton/goapn


Usage
    
        import "github.com/nicolaspaton/goapn"
        
        // ...
        
        // You can create multiple queues for different environments and apps
        q, err := apn.NewQueue(apn.Sandbox, "cert.pem", "key.pem")
        
        if err != nil {
            log.Fatalln("Error loading queue", err)
        }

        // The payload is a nested string to interface{} map that respects Apple doc [1]
        payload := make(map[string]interface{})
        payload["aps"] = map[string]interface{}{
            "alert": "You've got emails.",
            "badge": 9,
            "sound": "bingbong.aiff",
        }
        payload["foo"] = "bar"
        payload["answer"] = 42
        
        // Et hop, send! (0 for expiry means 1 year)
        q.Send <- apn.NewNotification("3f6e...device token here", payload, 0)

        // Start a loop in a goroutine somewhere to handle errors (before you start sending)
        // The erroneous notification is returned with an non null Error (os.Error) attribute
        // This interface handles internal validation errors and errors sent back by apple [2]
        go func(q *apn.Queue) {
            for {
                notification := <- q.Error
                if notification.Error != nil { // Error should always be there at this point...
                    // Do something with that notification
                }
            }
        }(q)


Certificates

You need a certification and an unprotected key pem file. See http://blog.boxedice.com/2010/06/05/how-to-renew-your-apple-push-notification-push-ssl-certificate/

Reminder, after you've got your .p12 files:

        openssl pkcs12 -clcerts -nokeys -out dev-cert.pem -in dev-cert.p12
        openssl pkcs12 -nocerts -out dev-key.pem -in dev-key.p12
        openssl rsa -in dev-key.pem -out dev-key-noenc.pem



License

BSD-style. See LICENSE file.


Apple and Apple Push Notifications are trademarks owned by Apple inc. and have nothing to do with the creator of this software.


[1] http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html%23//apple_ref/doc/uid/TP40008194-CH100-SW9

[2] http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html%23//apple_ref/doc/uid/TP40008194-CH101-SW4

[3] http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html%23//apple_ref/doc/uid/TP40008194-CH101-SW4



// Copyright 2011 Nicolas Paton. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

About

An Apple push Notification package for the Go language.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages