Skip to content

Instantly share code, notes, and snippets.

@fannar
Forked from greencoder/apns.sh
Last active March 10, 2022 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fannar/38b9116cf0fcdde7e4e65a12fe003eb7 to your computer and use it in GitHub Desktop.
Save fannar/38b9116cf0fcdde7e4e65a12fe003eb7 to your computer and use it in GitHub Desktop.
Curl the APNS http/2 API

Note: You MUST have curl 7.47+ with http/2 support compiled in

PEM

Convert P12 to PEM: openssl pkcs12 -in cert.p12 -out cert.pem -nodes -clcerts

curl -v \
-d '{"aps":{"alert":"<message>","badge":42}}' \
-H "apns-topic: <bundle id>" \
-H "apns-priority: 10" \
--http2 \
--cert <certificate file.pem> \
https://api.development.push.apple.com/3/device/<device token>

P12

curl -v \
-d '{"aps":{"alert":"<message>","badge":42}}' \
-H "apns-topic: <bundle id>" \
-H "apns-priority: 10" \
--http2 \
--cert-type P12 \
--cert <certificate file.p12>:<optional password> \
https://api.development.push.apple.com/3/device/<device token>

Token based

curl -v
     -H "apns-topic: com.example.MyApp"
     -H "authorization: bearer eyAia2lkIjogIjhZTDNHM1JSWDciIH0.eyAiaXNzIjogIkM4Nk5WOUpYM0QiLCAiaWF0IjogIjE0NTkxNDM1ODA2NTAiIH0.MEYCIQDzqyahmH1rz1s-LFNkylXEa2lZ_aOCX4daxxTZkVEGzwIhALvkClnx5m5eAT6Lxw7LZtEQcH6JENhJTMArwLf3sXwi"
     -H "apns-id : eabeae54-14a8-11e5-b60b-1697f925ec7b"
     -H "apns-push-type : alert"
     -H "apns-expiration  : 0"
     -H "apns-priority   : 10"
     --http2 --tlsv1.3 https://api.sandbox.push.apple.com/3/device/00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0
     -d "{"aps":{"alert":"hello"}}"

Apple

Sending Push Notifications Using Command-Line Tools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment