sslapple-push-notificationshttp2walletpasskit

Wallet pass push notifications APNs


So I have completed all the signing and compressing process for Apple passes and have been able to connect the pass to my server for updating. The only problem I have left to solve is implementing push notifications.

I have been trying for a couple of days now but just can't seem to manage and I think I am missing something really simple. I am not too proficient with networking so I would really appreciate the help.

This is the log I get from guzzle with my best try.

I am using the same certificate I used for the pass I am trying to update and am sending the device token I received upon registering the pass. This is my php code.

$client = new Client();
  try {
    $result = $client->post('https://api.push.apple.com:443', [
    'headers' => ['apns-id' => <pass_type_id> , ':path' => '/3/device/<device_id_received_upon_registration>'],
    'json' => ['apns'=>''],
    'debug'=>true,
    'version'=>2.0,
    'ssl_key'   => [<path_to_key>, <key_password>],
    'cert'      => [<path_to_certificate (same one used for signing pass)>, <certificate_password>]]);
    }
    catch (GuzzleHttp\Exception\ClientException $e) {
        dd($e);
    }

I am really lost with this one. Please help me out. I also tried connecting to port 1295 with some other code I copy pasted but it wasn't working as it should and had even more difficulty debugging as I am more familiar with port 443.


Solution

  • It works for me, with small changes:

    $pem_file       = '<path_to_your_pem_file_including_private_key>';
    $pem_secret     = '<private_key_password>';
    
    $url = "https://api.push.apple.com/3/device/" . $device_push_token;
    
    $response = $client->post($url, [
        'headers' => ['apns-topic' => $pass_type_id],
        'json' => json_decode('{}'),
        'debug' => true,
        'version' => 2.0,
        'cert' => [$pem_file, $pem_secret]
    ]);
    
    var_dump($response->getStatusCode());
    var_dump($response->getReasonPhrase());
    

    What is changed is the payload that needs to be empty JSON object (but present) and the header name for the topic, it is apns-topic not apns-id. I also constructed the URL directly, not via the headers and used a pem file with private key included in it, not sure if those matter.

    Maybe you should also check what you pass at the end of the URL, it is not the device_id, but the device_push_token.

    NB: remember to always send the wallet push notification to the production apple endpoint, not the sandbox!