Skip to content

Instantly share code, notes, and snippets.

@sideshow
Last active March 17, 2016 21:00
Show Gist options
  • Save sideshow/397f2d729fcf483ec304 to your computer and use it in GitHub Desktop.
Save sideshow/397f2d729fcf483ec304 to your computer and use it in GitHub Desktop.
apns2 http/2 example
package main
import (
"log"
"sync"
apns "github.com/sideshow/apns2"
"github.com/sideshow/apns2/certificate"
)
func main() {
var wg sync.WaitGroup
cert, pemErr := certificate.FromP12File("../cert.p12", "")
if pemErr != nil {
log.Println("Cert Error:", pemErr)
}
notification := &apns.Notification{}
notification.DeviceToken = "68bc7cd084111da3f7a297f6d9922aab704cbd4e8a4680d63b28b18746d0926e"
notification.Topic = "com.Apns2"
notification.Payload = []byte(`{"aps" : {"alert" : "Hello!"}}`)
client := apns.NewClient(cert).Production()
for i := 0; i < 100; i++ {
go func() {
wg.Add(1)
defer wg.Done()
res, err := client.Push(notification)
if err != nil {
log.Println("Error:", err)
return
}
log.Println(res)
}()
}
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment