Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Apple Enhanced Notification

I've been using this excellent blog post to try and get Apple Push Notifications working from my server. Connection seems to establish fine and I can write to it. However, no notification ever arrives. To try and debug it I'd like to construct an 'enhanced notification' which will make the APNS server return an error code before disconnecting. However, I'm unsure how to construct the data to send to the server using PHP.

Currently for a normal notification I am using, as per the tutorial post:

$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload;

This creates a request in the format:

alt text

However, I need a request in the format:

alt text

Where, according to the documentation:

Identifier—An arbitrary value that identifies this notification. This same identifier is returned in a error-response packet if APNs cannot interpret a notification.

Expiry—A fixed UNIX epoch date expressed in seconds (UTC) that identifies when the notification is no longer valid and can be discarded. The expiry value should be in network order (big endian). If the expiry value is positive, APNs tries to deliver the notification at least once. You can specify zero or a value less than zero to request that APNs not store the notification at all.

Any help in adapting the above code to tuse the above enhanced notification format would be much appreciated!

like image 225
JoeR Avatar asked Nov 18 '25 22:11

JoeR


1 Answers

$apnsMessage = 
    // new: Command "1"
    chr(1)
    // new: Identifier "1111"
    . chr(1) . chr(1) . chr(1) . chr(1)
    // new: Expiry "tomorrow"
    . pack('N', time() + 86400)
    // old 
    . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload;
like image 180
rik Avatar answered Nov 21 '25 13:11

rik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!