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;
}
?>
switch
andcase
instead of all of thoseelse ifs
, it'd be easier to maintain. However, are you trying to contact the APNS server using sandbox tokens? If that's the case then you will receive that error. You may also need to republish the production certificate as the private key might have become bad? – Oscular