Skip to content

Instantly share code, notes, and snippets.

@egcode
Last active August 21, 2020 09:19
Show Gist options
  • Save egcode/386ff9b15a1f8b63ae89b8ab6cd8c93f to your computer and use it in GitHub Desktop.
Save egcode/386ff9b15a1f8b63ae89b8ab6cd8c93f to your computer and use it in GitHub Desktop.
push notification curl
#!/bin/bash
# to execute it first chmod +x push.sh
deviceToken=<device token id from device did receive token>
authKey="./AuthKey_<auth_key>.p8"
authKeyId=<auth_key>
teamId=<team id>
bundleId=<bundle id>
endpoint=https://api.development.push.apple.com
read -r -d '' payload <<-'EOF'
{
"aps": {
"badge": 2,
"sound" : "default",
"category": "mycategory",
"alert": {
"title": "my title bla",
"subtitle": "my subtitle",
"body": "my body text message"
}
},
"custom": {
"mykey": "myvalue"
}
}
EOF
# --------------------------------------------------------------------------
base64() {
openssl base64 -e -A | tr -- '+/' '-_' | tr -d =
}
sign() {
printf "$1"| openssl dgst -binary -sha256 -sign "$authKey" | base64
}
time=$(date +%s)
header=$(printf '{ "alg": "ES256", "kid": "%s" }' "$authKeyId" | base64)
claims=$(printf '{ "iss": "%s", "iat": %d }' "$teamId" "$time" | base64)
jwt="$header.$claims.$(sign $header.$claims)"
curl --verbose \
--header "content-type: application/json" \
--header "authorization: bearer $jwt" \
--header "apns-topic: $bundleId" \
--data "$payload" \
$endpoint/3/device/$deviceToken
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment