Push notification from Apple wallet Pass doesn't appear on the phone

Hi, everyone!
I'm trying to do push notification for apple wallet pass via PHP. My code (in 2 variants) is below. According to guidelines I should get the response in json format, but i don't. Anyway in the server logs I see the response 200. Any notification doesn't appear on the device.
I also tried to push notification via command line tools, but also faced problems - the guideline give info only about push notification for your own app, not for the Wallet.

I will be very grateful for any responses.

№1
Code Block
$apnsServer = 'tcp://api.push.apple.com:443/3/device/';
$privateKeyPassword = '<password>';
$message = 'test';
$deviceToken =
'<token>';
$pushCertAndKeyPemFile = 'my.pem';
$stream = stream_context_create();
stream_context_set_option($stream,
'ssl',
'passphrase',
$privateKeyPassword);
stream_context_set_option($stream,
'ssl',
'local_cert',
$pushCertAndKeyPemFile);
$connectionTimeout = 20;
$connectionType = STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT;
$connection = stream_socket_client($apnsServer,
$errorNumber,
$errorString,
$connectionTimeout,
$connectionType,
$stream);
if (!$connection){
echo "Failed to connect to the APNS server. Error no = $errorNumber<br/>";
exit;
} else {
echo "Successfully connected to the APNS. Processing...</br>";
}
$messageBody['aps'] = array('alert' => $message,
'sound' => 'default',
'badge' => 2,
);
$payload = json_encode($messageBody);
$notification = chr(0) .
pack('n', 32) .
pack('H*', $deviceToken) .
pack('n', strlen($payload)) .
$payload;
$wroteSuccessfully = fwrite($connection, $notification, strlen($notification));
$apple_error_response = fread($connection, 6);
if (!$wroteSuccessfully){
echo "Could not send the message<br/>";
}
else {
echo "Successfully sent the message<br/>";
}
fclose($connection);
?>


№2
Code Block
$apnsCert = 'my.pem';
$push_token = '<token>';
$passIdentify = '<pass identify>';
$payload['aps'] = array('alert' => 'Oh hai!', 'badge' => 1, 'sound' => 'default');
$output = json_encode($payload);
$msg = chr(0) . pack('n', 32) . pack('H*', $push_token) . pack('n', strlen($output)) . $output . pack('n', strlen($passIdentify)) . $passIdentify;
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
$apns = stream_socket_client("api.push.apple.com:443/3/device/", $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
if (!$apns)
exit ("APNS Connection Failed: $error $errorString" . PHP_EOL);
var_dump($apns);
if(fwrite($apns, $msg)) {
echo "ok";
} else {
echo "not ok ".error_reporting(E_ALL);
}
socket_close($apns);
fclose($apns);



  • Hi @juljul, I saw that you are from Belarus. Did you manage to sort out the question? I ran into the same problems and so far I can't find a normal description of how to work with guns and update cards

Add a Comment

Replies

You don't need to send any push notifications directly to Wallet.

You should send empty push notifications to apple push notifications service and it will make Wallet downloads new version of pass and shows notifications with messages you specified in json file of your pass.