Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending APNS command = 2

I've got a problem sending level 2 notifications to APNS. The v1 are sending ok, but I'd like to move to v2. Below are my two methods that implement both versions. I separated these from the rest of the code to easily change between the two. The v1 works, while the v2 does not..

static function createNotificationV1($token, $payload, $id, $expireTime)
{
    $msg = pack('C', 1); // v1
    $msg .= pack('N', $id); // id
    $msg .= pack('N', $expireTime);
    $msg .= pack('n', 32) . pack('H*', $token);
    $msg .= pack('n', strlen($payload)) . $payload;

    return $msg;
}

static function createNotificationV2($token, $payload, $id, $expireTime)
{
    $tokenItem = pack('C', 1) . pack('n', 32) . pack('H*', $token);
    $payloadItem = pack('C', 2) . pack('n', strlen($payload)) . $payload;
    $idItem = pack('C', 3) . pack('n', 4) . pack('N', $id);
    $expireItem = pack('C', 4) . pack('n', 4) . pack('N', $expireTime);
    $priorityItem = pack('C', 5) . pack('n', 1) . pack('C', 10);

    $frame = $tokenItem . $payloadItem . $idItem . $expireItem . $priorityItem;

    $msg = pack('C', 2); // v2
    $msg .= pack('n', strlen($frame));
    $msg .= $frame;

    return $msg;
}

Any tips would be greatly appreciated.

like image 559
Pvel Avatar asked May 13 '26 03:05

Pvel


1 Answers

This code is working great:

$pn = pack('CnH*', 1, 32, $token)
    . pack('CnA*', 2, strlen($payload), $payload)
    . pack('CnA*', 3, 4, $id)
    . pack('CnN',  4, 4, $expireTime)
    . pack('CnC',  5, 1, 10);

$msg = pack('CN', 2, strlen($pn)) . $pn;

Because your are using pack('n', strlen($frame)) instead of pack('N',

like image 100
mths Avatar answered May 15 '26 18:05

mths



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!