()
| 11 | ) |
| 12 | |
| 13 | func 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 | } |
nothing calls this directly
no test coverage detected