Skip to content

Instantly share code, notes, and snippets.

@sideshow
Last active July 19, 2023 00:03
Show Gist options
  • Save sideshow/ae221a792261180c954d9bea72780f85 to your computer and use it in GitHub Desktop.
Save sideshow/ae221a792261180c954d9bea72780f85 to your computer and use it in GitHub Desktop.
apns.go
package main
import (
"log"
"sync"
"github.com/sideshow/apns2"
"github.com/sideshow/apns2/certificate"
)
// Run this from the terminal;
// bash> GODEBUG=http2debug=2 go run ./apns.go
func main() {
cert, pemErr := certificate.FromP12File("../cert.p12", "")
if pemErr != nil {
log.Println("Cert Error:", pemErr)
}
notification := &apns2.Notification{}
notification.DeviceToken = "11aa01229f15f0f0c52029d8cf8cd0aeaf2365fe4cebc4af26cd6d76b7919ef7"
notification.Topic = "com.sideshow.Apns2"
notification.Payload = []byte(`{"aps" : {"alert" : "Hello!"}}`)
client := apns2.NewClient(cert).Production()
log.Println("Starting push")
var wg sync.WaitGroup
for i := 0; i < 100000; i++ {
wg.Add(1)
go func() {
client.Push(notification)
wg.Done()
}()
}
wg.Wait()
log.Println("Im done!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment