MCPcopy
hub / github.com/sideshow/apns2 / main

Function main

_example/basic/main.go:13–47  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11)
12
13func main() {
14 certPath := flag.String("cert", "", "Path to .p12 certificate file (Required)")
15 token := flag.String("token", "", "Push token (Required)")
16 topic := flag.String("topic", "", "Topic (Required)")
17 flag.Parse()
18
19 if *certPath == "" || *token == "" || *topic == "" {
20 flag.PrintDefaults()
21 os.Exit(1)
22 }
23
24 cert, err := certificate.FromP12File(*certPath, "")
25 if err != nil {
26 log.Fatal("Cert Error:", err)
27 }
28
29 notification := &apns2.Notification{}
30 notification.DeviceToken = *token
31 notification.Topic = *topic
32 notification.Payload = []byte(`{
33 "aps" : {
34 "alert" : "Hello!"
35 }
36 }
37 `)
38
39 client := apns2.NewClient(cert).Production()
40 res, err := client.Push(notification)
41
42 if err != nil {
43 log.Fatal("Error:", err)
44 }
45
46 fmt.Printf("%v %v %v\n", res.StatusCode, res.ApnsID, res.Reason)
47}

Callers

nothing calls this directly

Calls 4

FromP12FileFunction · 0.92
NewClientFunction · 0.92
ProductionMethod · 0.80
PushMethod · 0.80

Tested by

no test coverage detected