Use curl to test apple push message for new push certs in pem format

To perform push message testing on your local Mac, here’s what you need

  1. PEM encoded certificate to connect to the APNs sandbox
  2. PEM encoded private key, for the above certificate
  3. App ID (Topic)
  4. device push token

curl -v --header "apns-topic: ${APP_ID}"\
  --header "apns-push-type: alert" \
  --cert "${APN_CERTIFICATE}" \
  --cert-type PEM \
  --key "${APN_CERTIFICATE_KEY}" \
  --key-type PEM \
  --data '{"aps":{"alert":"test message, please ignore me."}}' \
  --http2  https://${APNS_HOST_NAME}/3/device/${DEVICE_TOKEN}

As an example,
let’s consider a scenario where you have a directory named apple_push_message_test located in your local Mac path.

In this directory,
you have two files:
apn_certificate.pem (~/apple_push_message_test/apn_certificate.pem) and
apn_private_key.pem (~/apple_push_message_test/apn_private_key.pem).

The former contains your Apple Push Notification (APN) certificate,
while the latter contains your APN private key.

Additionally, you have an app with the identifier com.tenderprog.org,
which is the APP_ID you should replace with your own app identifier.

Lastly, you have a device token for testing purposes with the value
740f4707bebcf74f9b7c25d48e3358945f6aa01da5ddb387462c7eaf61bb78ad.


APP_ID="com.tenderprog.org"
APN_CERTIFICATE="~/apple_push_message_test/apn_certificate.pem"
APN_CERTIFICATE_KEY="~/apple_push_message_test/apn_private_key.pem"
DEVICE_TOKEN="740f4707bebcf74f9b7c25d48e3358945f6aa01da5ddb387462c7eaf61bb78ad"
APNS_HOST_NAME="api.sandbox.push.apple.com"

curl -v --header "apns-topic: ${APP_ID}"\
  --header "apns-push-type: alert" \
  --cert "${APN_CERTIFICATE}" \
  --cert-type PEM \
  --key "${APN_CERTIFICATE_KEY}" \
  --key-type PEM \
  --data '{"aps":{"alert":"test message, please ignore me."}}' \
  --http2  https://${APNS_HOST_NAME}/3/device/${DEVICE_TOKEN}