Testing your iOS APNS certificate — A developer’s help guide.

Kavitha Kumarasamy
2 min readNov 9, 2017

--

Have you ever faced a problem of server yeilding output, “APNS push certificate .pem is ‘not working’,’invalid’?” Have you been testing by placing the certificate in server and if it fails with error,ended up generating a new one without knowing what and where it went wrong?

I had the same issue.So to solve this problem, I wrote a unit test using cCurl command to check if .pem is working and send test notifications to your device.(provided you know your device token.)

Lets go step by step,

/usr/local/Cellar/curl/7.54.1/bin/curl -v \-d '{"aps":{"alert":"test","sound":"default"}}' \-H "apns-topic:com.yourcompanyname.yourappname" \-H "apns-expiration: 1" \-H "apns-priority: 10" \--http2 \--cert yourpempath:yourpempassword \https://api.development.push.apple.com/3/device/yourdevicetoken
  • Test your production .pem certificate using following command.
/usr/local/Cellar/curl/7.54.1/bin/curl -v \-d ‘{“aps”:{“alert”:”test”,”sound”:”default”}}’ \-H “apns-topic:com.yourcompanyname.yourappname” \-H “apns-expiration: 1” \-H “apns-priority: 10” \ — http2 \ — cert yourpempath:yourpempassword \https://api.push.apple.com/3/device/yourdevicetoken
  • You will get few logs running and finally status code 200 if success!!! Tada!

If there happens to be some error with .pem or any issues, your logs will be self explanatory.

Hope this helps in solving and making right from our end on .pem certificate creation and push notification unit testing even before server comes into a picture.

Note :

If you are a Java Fan you can try this. I haven’t tried though!

--

--

Kavitha Kumarasamy

iOS freak | mobile developer | front end developer | Reactjs | React-Native | dancer | A Mother | Marvel fan | Cyclist | Table Tennis enthusiast | a learner.