Warning on pack() in the push notifications script
I'm writing my push notifications script in PHP.
the $deviceToken
is correct, but I've a warning in this line:
$b = pack('H*', str_replace(' ', '', $deviceToken));
the warning is this:
开发者_高级运维Warning: pack() [function.pack]: Type H: illegal hex digit in /myurl.com/send_push_notification.php on line 33
And the notification doesn't arrive.
Do you know why?
I had the same problem. I ended up using
trim($device_token)
instead of
str_replace(' ', '', $deviceToken)
Fixed the issue in the end.
I had the same problem. Finally, I found that there was a space character in my URL! So, just check your URL, perhaps that's the error.
I also suffered from the same problem. It solved my issue. try using below code:
chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $item[0])) . chr(0) . chr(strlen($payload)) . $payload;
If anyone is still having this issue, try
$deviceToken = pack('H*', str_replace(' ', '', sprintf('%u', CRC32($deviceToken))));
精彩评论