I have already read this question APNS Development [sandbox] vs Production , but it didn't help me.
My question is, how to use production cert in development. Here is my code, if I want to use apns in the development, I have to set client := apns2.NewClient(cert).Development()
. Now I don't want to switch back and forth between production and development every time. What I can think of is to add a judgment,
if _, err := os.Stat("/path/to/debugfile"); err == nil {//Debugfile is just a file
client := apns2.NewClient(cert).Decelopment()
} else if os.IsNotExist(err) {
client := apns2.NewClient(cert).Production()
}
I want to know, i can use production cert in development.
What does this sentence mean? How to use production certificates in development without judging the existence of debugfile?
func ApplePushNotificationService(deviceToken string, parameters string) {
cert, err := certificate.FromP12File("./hookupAPNS.p12", "******") //p12.filename
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)
}