简体   繁体   English

Iphone推送通知设备令牌错误

[英]Iphone Push Notification Wrong Device Token

Finally,I found out the sandbox tokens,which were mixed with the production tokens,and I update the code,receive the error response from apple,when post a sandbox token to apple,the next tokens all failed....While the push msg was "$payload['aps'] = array('content-available' => 1); ",apple will push the msg ,but the device will not show this msg,when I find the wrong one,I delete it,and retest. 最后,我找出了与生产令牌混合的沙箱令牌,并更新了代码,从苹果那里收到了错误响应,当将沙箱令牌发布到苹果时,下一个令牌都失败了。味精是“ $ payload ['aps'] = array('content-available'=> 1);”,苹果会推送味精,但是当我发现错误的消息时,设备将不会显示该味精,将其删除,然后重新测试。

There is an amusing problem of apple push notification service: when I generate a post notification for my device and send to apple's server,for a while,my device will receive the notification. 苹果推送通知服务存在一个有趣的问题:当我为设备生成发布通知并发送到苹果服务器时,我的设备会在一段时间内收到该通知。 But if I first post a notification by a wrong devicetoken,then post a right notification to my device,my device will be responseless,just like the push notification was eaten by apple? 但是,如果我先通过错误的设备令牌发布通知,然后将正确的通知发布到我的设备,我的设备将无响应,就像推送通知被苹果吃掉了一样吗?

What wrong with this? 这怎么了

I use php code for push service,here is the most important part: 我使用php代码进行推送服务,这是最重要的部分:

$payload['aps'] = array('content-available' => 1);
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
        foreach ($line as $deviceToken) {
            break;
        }

        print_r($deviceToken);
        $apnsMessage = chr(1) . $time . $time . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload;
        $ret = fwrite($apns, $apnsMessage);
        if ($ret !== strlen($apnsMessage)) {
            echo "push error";
        }

        ob_flush();
        flush();

        $read = array($apns);
        $null = null;
        $changedStreams = stream_select($read, $null, $null, 0, 100000);//wait for 0.1s

        if ($changedStreams === false) {    
            echo "Error: Unabled to wait for a stream availability";
        } elseif ($changedStreams > 0) {
            print "can't receive any notification behind this token";

            $responseBinary = fread($apns, 6);
            if ($responseBinary !== false || strlen($responseBinary) == 6) {

                $response = unpack('Ccommand/Cstatus_code/Nidentifier', $responseBinary);
                print_r($response);
            }
        } else {
            //update the success push status in database
        }

        print "<br>";
    }

I dont know what's wrong with this,and I have also add feedback service in another php,and get none wrong token from apple,Because I have many devicetoken in my database,I cant find which one of them is wrong. 我不知道这是怎么回事,并且我还在另一个PHP中添加了反馈服务,并且没有从Apple获得任何错误的令牌,因为我的数据库中有许多devicetoken,所以我找不到其中哪一个是错误的。

Someone help me,forgive my poor english 有人帮助我,请原谅我可怜的英语

Assuming your $apns is implemented in this way 假设您的$apns是通过这种方式实现的

$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2,STREAM_CLIENT_CONNECT, $streamContext);

you should check the $errorString to find out the error. 您应该检查$ errorString以找出错误。

or try to close the socket for each message and see if there is any difference 或尝试关闭每个消息的套接字,看看是否有任何区别

fwrite($apns, $apnsMessage);
socket_close($apns);
fclose($apns);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM