swiftterminalapple-push-notificationscallkit

I want to send call notification from terminal using .pem


I want to send call notification using terminal and .pem file. all code looking good at my end. terminal throw this error.

enter image description here

pushregistrytoken retrieve from app and try this command on terminal.

curl -v -d '{"aps":{"alert":"hello"}}' --http2 --cert Certificates.pem:1234 https://api.development.push.apple.com/3/device/pushregistrytoken

here i use http2 protocol

Resource : https://websitebeaver.com/callkit-swift-tutorial-super-easy

i am working with terminal to send notification for first time.

Thanks.


Solution

  • The old certificate and password way is no longer works ,you need to create an AuthKey.p8 along with it's authKey and replace the entries here according to your developer settings , then wrap the below code inside File.sh and execute it from terminal $ bash pathToFile/File.sh

    #!/bin/bash
    
    deviceToken="tokenHere"
    authKey="pathTo........./AuthKey.p8"
    authKeyId="......."
    teamId="........"
    bundleId="........"
    endpoint="https://api.sandbox.push.apple.com:2197"
    apns_collapse_id="send_update"
    
    read -r -d '' payload <<-'EOF'
    {
       "aps": {
          "badge": 2,
          "category": "mycategory",
          "alert": {
             "title": "my title",
             "subtitle": "my subtitle",
             "body": "my body text message 103"
          }
       },
       "custom": {
          "id": "1234"
       }
    }
    
    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" \
       --header "apns-collapse-id: $apns_collapse_id"\
       --http2 \
       --data "$payload" \
       $endpoint/3/device/$deviceToken