We do have some issues with sending Pushes via APNS. As it seems we do get wrong responses from apple. The push is sent, but we do get an error response, which leads to pushes sent multiple times. Has anybody else experienced similar problems or do I miss something?
<?php
private function checkAppleErrorResponse($apns, PushToken $token)
{
//byte1=always 8, byte2=StatusCode, bytes3,4,5,6=identifier(rowID). Should return nothing if OK.
$apple_error_response = fread($apns, 6);
if ($apple_error_response) {
//unpack the error response (first byte 'command" should always be 8)
$error_response = unpack('Ccommand/Cstatus_code/Nidentifier', $apple_error_response);
if ($error_response['status_code'] == '0') {
$error_response['status_code'] = '0-No errors encountered';
} else if ($error_response['status_code'] == '1') {
$error_response['status_code'] = '1-Processing error';
} else if ($error_response['status_code'] == '2') {
$error_response['status_code'] = '2-Missing device token';
} else if ($error_response['status_code'] == '3') {
$error_response['status_code'] = '3-Missing topic';
} else if ($error_response['status_code'] == '4') {
$error_response['status_code'] = '4-Missing payload';
} else if ($error_response['status_code'] == '5') {
$error_response['status_code'] = '5-Invalid token size';
} else if ($error_response['status_code'] == '6') {
$error_response['status_code'] = '6-Invalid topic size';
} else if ($error_response['status_code'] == '7') {
$error_response['status_code'] = '7-Invalid payload size';
} else if ($error_response['status_code'] == '8') {
$error_response['status_code'] = '8-Invalid token';
} else if ($error_response['status_code'] == '255') {
$error_response['status_code'] = '255-None (unknown)';
} else {
$error_response['status_code'] = $error_response['status_code'] . '-Not listed';
}
if ($token->isExistingUser()) {
$this->logger->error('#cloudalarm User-Id: ' . $token->getAssociatedUser() . ': Something went wrong with APNS pushing , error is ' . $error_response['status_code']);
} else {
$this->logger->error('#cloudalarm for simple login id ' . $token->getAssociatedUser() . ': Something went wrong with APNS pushing , error is ' . $error_response['status_code']);
}
return true;
}
return false;
}
?>
I think you are misunderstanding the error. Typically the response codes are meant to help you manage your list. If you get an "invalid token" error it is typically accompanied by an updated token, remove the invalid one and insert the new one in it's place. Keep in mind that APNS does 'forward' the message automatically and the notice is just to help you stay up to date.
If you are not getting the updated token then it could be that your app was deleted and not reinstalled so the token is simply invalid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With