Reputation: 185
I having trouble with a push notification script in PHP, but it's depending of the Token.
I have some tokens which after conversion (with pack()) seem to be on 2 lines.
So when I write on the socket, all the rest of my packet don't receive the push.
I tryed a very simple script with 4 Tokens.
I have a very strange token : "2f9c2239c85e4705171e379691ace8fd0e68ad984912de530a1f969ebb655fd7" when I try to send a push to this one, nothing are sent.
If I put this token at the end, the first token will receive the push, if I put it in the second position, only the first device will receive the push....
When I'm debuging, I can see a line break but I'm not sure that it's the problem
Token : string(64) "2f9c2239c85e4705171e379691ace8fd0e68ad984912de530a1f969ebb655fd7"
Concersion: string(131) " /�"9�^G7�����h��I�S
���e_�^{"aps":{"alert":"Xxxxx XX - Test - Push"},"main_node_id":"756516","contentobject_id":"634997"}"
Token: string(64) "b0ddb6a64fb546494d14759d1f62050fa6bab81a8bd34a2448eb9c6a650adc21"
Conversion: string(131) " �ݶ�O�FIMu�b�����J$H�je
�!^{"aps":{"alert":"Xxxxx XX - Test - Push"},"main_node_id":"756516","contentobject_id":"634997"}"
Token : string(64) "3a7c392fc642b946a5604579ef3fce8174dcb9eb70688d9d429ab3000427638a"
Conversion: string(131) " :|9/�B�F�`Ey�?tܹ�ph��B��'c�^{"aps":{"alert":"Xxxxx XX - Test - Push"},"main_node_id":"756516","contentobject_id":"634997"}"
Token : string(64) "2a4c36091a2169d1276e14d657b8d58a98b8a10b0376980adb8706ff87737ee4"
Conversion: string(131) " *L6 !i�'n�W�Պ���
v�
ۇ��s~�^{"aps":{"alert":"Xxxxx XX - Test - Push"},"main_node_id":"756516","contentobject_id":"634997"}"
Here is my PHP function to create the packet send to the socket : (I tryed with some other library.. it was the same)
protected function _buildPacket( array $body, $token ) {
$payload = json_encode( $body );
return chr( 0 ) . pack( "n", 32 ) . pack( 'H*', str_replace( ' ', '', $token ) ) . pack( "n", strlen( $payload ) ) . $payload;
}
Do you have already seen that ?
Note, that I reuse the same socket, so this token breaks something but I don't understand what.
Thank you for your help
Upvotes: 2
Views: 288
Reputation: 393811
According to what you describe, the 2f9c2239c85e4705171e379691ace8fd0e68ad984912de530a1f969ebb655fd7
token is invalid. Perhaps it's a sandbox token and you are using it to push to the production environment or vice versa.
When you send a push notification with an invalid device token to the APNS server, Apple return an error response (if you are using the newer binary format) and closes the socket. Therefore, any messages that were sent through the same socket after the one with the invalid token will be discarded, and need to be resent through a new socket. That's why you encounter different results depending on the order of the messages.
Read some more about error handling of Apple Push Notifications here.
Upvotes: 2