I call apns2 in golang, which sometimes returns a timeout and the process will close. I am using go version go1.12.5 darwin / amd64. I have reviewed apns2's issues #24 and #21, I guess they have solved it, but there will still be problems.
This is my code
func ApplePushNotificationService(deviceToken string, parameters string) {
cert, err := certificate.FromP12File("./hookupAPNS.p12", "******")
if err != nil {
log.Fatal("Cert Error:", err)
}
notification := &apns2.Notification{}
notification.DeviceToken = deviceToken
notification.Topic = "com.preferme.hookup"
payload := payload.NewPayload().Alert(parameters).AlertBody(parameters).Badge(1).Sound("sound.wav").Custom("key", "val")
notification.Payload = payload
client := apns2.NewClient(cert).Production()
res, err := client.Push(notification)
if err != nil {
log.Fatal("push Error:", err)
}
fmt.Printf("%v %v %v
", res.StatusCode, res.ApnsID, res.Reason)
}
This is the last log of the process shutdown.
push Error:Post https://api.development.push.apple.com/3/device/4dc8efa9c46b0206c2e6e0dda6a1314c457704f897747ae1f7dffe4ef31a443b: dial tcp: lookup api.development.push.apple.com on 10.143.22.116:53: read udp 10.116.213.185:38055->10.143.22.116:53: i/o timeout