Last active
March 17, 2016 21:00
-
-
Save sideshow/397f2d729fcf483ec304 to your computer and use it in GitHub Desktop.
apns2 http/2 example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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