Last active
July 15, 2023 02:54
-
-
Save yonat/b14672e52c1e3ddbae1912024f50f0a6 to your computer and use it in GitHub Desktop.
Send Apple push notification from terminal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
show_help() { | |
echo "" | |
echo " $(basename "$0") - Send push notification to an iOS device." | |
echo "" | |
echo " Usage:" | |
echo " $(basename "$0") [options] <app-bundle-id> <cert-file.p12> <cert-password> <push-token>" | |
echo "" | |
echo " Options:" | |
echo " -p <payload-json-file-path>" | |
echo " -s\tSilent push" | |
echo " -d\tSend to Debug app (sandbox environment)" | |
} | |
while getopts "p:sd" OPTION | |
do | |
case $OPTION in | |
p) | |
payload_file="$OPTARG" | |
;; | |
s) | |
silent=true | |
;; | |
d) | |
debug=.development | |
;; | |
?) | |
show_help | |
exit 1 | |
;; | |
esac | |
done | |
shift $(($OPTIND - 1)) | |
if [[ $# -ne 4 ]]; then | |
show_help | |
exit 1 | |
fi | |
app=$1 | |
cert=$2 | |
password=$3 | |
token=$4 | |
if [[ -z "$silent" ]]; then | |
priority=10 | |
type=alert | |
payload='"alert" : { "title" : "Test Push", "body" : "Did you get it?" }' | |
else | |
priority=5 | |
type=background | |
payload='"content-available" : true' | |
fi | |
if [[ -z "$payload_file" ]]; then | |
json="{\"aps\" : { $payload }, \"pushType\" : \"0\" }" | |
else | |
json=$(cat "$payload_file") | |
fi | |
curl -v --http2 \ | |
--data "$json" \ | |
--header "apns-push-type: $type" \ | |
--header "apns-priority: $priority" \ | |
--header "apns-topic: $app" \ | |
--cert-type P12 --cert "$cert:$password" \ | |
"https://api$debug.push.apple.com/3/device/$token" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment