Search code examples
phpiosapple-push-notifications

Sending APNs VoIP notification return InvalidPushType


I'm trying send a voip push notification but it's return InvalidPushType, how you can see in the image.

enter image description here

And my code to make the request with Curl PHP

if (defined("CURL_VERSION_HTTP2") && (curl_version()["features"] & CURL_VERSION_HTTP2) !== 0) {

     $device_token = "1302E8106AA322DE917B2D0F0FC4D656878F878E8E2FCEA9CEA153D3C80027C7";
     $body["aps"] = array(
        "alert" => "callIOS",
        "id" => "eabeae54-14a8-11e5-b60b-1697f925ec7b",
        "nameCaller" => "Hien Nguyen",
        "handle" => "0123456789",
        "isVideo" => true
     );

     $header[] = "apns-topic: ao.test.app";
     $header[] = "apns-expiration: 0";
     $header[] = "apns-priority: 10";
     $header[] = "apns-push-type: voip";
     $header[] = "Content-Type: application/x-www-form-urlencoded";
     $header[] = "apns-id: eabeae54-14a8-11e5-b60b-1697f925ec7b";

     $ch = curl_init();
     $url = "https://api.sandbox.push.apple.com/3/device/" . $device_token;
     curl_setopt($ch,CURLOPT_URL,$url);
     curl_setopt($ch,CURLOPT_POST, 1);             
     curl_setopt($ch,CURLOPT_HTTPHEADER, $header);
     curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($body));
     curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch,CURLOPT_SSLCERT, "VOIP.pem");
     curl_setopt($ch,CURLOPT_SSLCERTPASSWD, "");

     $response = curl_exec($ch);
     $err = curl_error($ch);

     print_r(json_decode($response));
     print_r(json_decode($err));
     curl_close($ch);
  } else {
     echo "No HTTP/2 support on client.";
  }

I'm following the official doc here

Edit: I try add .voip at the end of apns-topic (ao.test.app.voip), don't work.


Solution

  • Solved

    I was getting the wrong APNs token, the right way to get APNs token in flutter is colling this function:

    await FlutterCallkitIncoming.getDevicePushTokenVoIP()