ApnsPHP
ApnsPHP copied to clipboard
Unable to send notification, don't see the problem
Hi!
I am trying to use this ApnsPHP. I am using a basic code example:
$devices` = array(
'08b38a49f70fa0639fee1e9d1b4890f8599ecbe7feb571b763242d4fef1b25e0',
'1e82db91c7ceddd72bf33d74ae052ac9c84a065b35148ac401388843106a7485',
);
$push = new ApnsPHP_Push(
ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,
self::$APN_CERT_PATH
);
$push->setProviderCertificatePassphrase(self::$APN_CERT_PASS);
$push->setRootCertificationAuthority(self::$APN_CERT_PATH);
$push->connect();
$cont = 1;
foreach ( $devices as $token ) {
$message = new ApnsPHP_Message($token);
$message->setCustomIdentifier("Message-Badge$cont");
$message->setBadge(1);
$message->setText('Hello APNs-enabled device!');
$message->setSound();
$message->setExpiry(30);
$push->add($message);
$cont++;
}
$push->send();
$push->disconnect();
$aErrorQueue = $push->getErrors();
if (!empty($aErrorQueue)) {
var_dump($aErrorQueue);
echo "<br><br>";
}
}
The first device token came from my iPhone test device (I am using phonegap-push-plugin to get this token).
This is the response from the script:
Wed, 25 May 2016 10:38:28 +0200 ApnsPHP[1073]: INFO: Trying tls://gateway.sandbox.push.apple.com:2195...
Wed, 25 May 2016 10:38:28 +0200 ApnsPHP[1073]: INFO: Connected to tls://gateway.sandbox.push.apple.com:2195. Wed, 25 May 2016 10:38:28 +0200 ApnsPHP[1073]: INFO: Sending messages queue, run #1: 2 message(s) left in queue.
Wed, 25 May 2016 10:38:28 +0200 ApnsPHP[1073]: STATUS: Sending message ID 1 [custom identifier: Message-Badge1] (1/3): 119 bytes. Wed, 25 May 2016 10:38:28 +0200 ApnsPHP[1073]: STATUS: Sending message ID 2 [custom identifier: Message-Badge2] (1/3): 119 bytes.
Wed, 25 May 2016 10:38:28 +0200 ApnsPHP[1073]: ERROR: Unable to send message ID 1: Invalid token (8). Wed, 25 May 2016 10:38:28 +0200 ApnsPHP[1073]: INFO: Disconnected.
Wed, 25 May 2016 10:38:28 +0200 ApnsPHP[1073]: INFO: Trying tls://gateway.sandbox.push.apple.com:2195... Wed, 25 May 2016 10:38:29 +0200 ApnsPHP[1073]: INFO: Connected to tls://gateway.sandbox.push.apple.com:2195.
Wed, 25 May 2016 10:38:29 +0200 ApnsPHP[1073]: INFO: Sending messages queue, run #2: 2 message(s) left in queue. Wed, 25 May 2016 10:38:29 +0200 ApnsPHP[1073]: WARNING: Message ID 1 [custom identifier: Message-Badge1] has an unrecoverable error (8), removing from queue without retrying...
Wed, 25 May 2016 10:38:29 +0200 ApnsPHP[1073]: STATUS: Sending message ID 2 [custom identifier: Message-Badge2] (1/3): 119 bytes. Wed, 25 May 2016 10:38:30 +0200 ApnsPHP[1073]: INFO: Disconnected.
array (size=1)
1 =>
array (size=3)
'MESSAGE' =>
object(ApnsPHP_Message)[845]
protected '_bAutoAdjustLongPayload' => boolean true
protected '_aDeviceTokens' =>
array (size=1)
0 => string '08b38a49f70fa0639fee1e9d1b4890f8599ecbe7feb571b763242d4fef1b25e0' (length=64)
protected '_sText' => string 'Hello APNs-enabled device!' (length=26)
protected '_nBadge' => int 1
protected '_sSound' => string 'default' (length=7)
protected '_sCategory' => null
protected '_bContentAvailable' => null
protected '_aCustomProperties' => null
protected '_nExpiryValue' => int 30
protected '_mCustomIdentifier' => string 'Message-Badge1' (length=14)
'BINARY_NOTIFICATION' => string '���WEd�� ��I��c���H��Y�����q�c$-O�%��J{"aps":{"alert":"Hello APNs-enabled device!","badge":1,"sound":"default"}}' (length=119)
'ERRORS' =>
array (size=1)
0 =>
array (size=5)
'command' => int 8
'statusCode' => int 8
'identifier' => int 1
'time' => int 1464165508
'statusMessage' => string 'Invalid token' (length=13)
I cant see the problem with the first token. Of course, I am not receiving nothing into my device.
Can anybody help me please?
Regards
Facing same issue :(
The most likely explanation is that you are sending a push notification with a sandbox device token to the production APNS server or wise versa. It was my case - by switching all combinations ApnsPHP_Abstract::ENVIRONMENT_*
and dev/prod.pem
files I found combination that started working.