从我们的服务器发送推送通知时胜负的关键 [英] Critical outcome when sending push notification from our server

查看:161
本文介绍了从我们的服务器发送推送通知时胜负的关键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个应用程序在AppStore上,并与注册的推送通知。他们成功地工作所有的时间,但我们现在试图发送一个全球性推动,奇怪的事情发生了。这是我们在我们的服务器端的PHP文件:

We have an app on appstore, and with registered push notifications. They have successfully worked all the time, but we now tried to send a 'global' push, and something weird happened. This is what we have in our server-side .php file:

//Loop through tokens in tokenArray
$i = 0;
$t = 0;
foreach($tokenArray as $token)
{
    $t++;
    // Make notification
    $msg = chr(0) . pack('n', 32) . pack('H*', $token) . pack('n', strlen($payload)) . $payload;

    // Send
    $result;
    if($message != null)
    {
        $result = fwrite($fp, $msg, strlen($msg));
    }

if ($result)
    $i++;
}
// Close the connection to the server
fclose($fp);

if($i == 0)
{
    echo 'The message was not delivered to anyone out of '.$t.'.';
}
else
{
    echo 'The message was delivered to '.$i.' out of '.$t.'.';
}

在此之前的code一直成功,这一种仍然如此。该tokenArray包含令牌表,如 SELECT标记与从令牌; 从我们的SQL。这工作。

The code before this has always worked, and it kind of still does. The tokenArray contains the table with tokens, as in SELECT Token FROM Tokens; from our SQL. This works.

在开发过程中,当只有我们自己令牌进行了登记,它总是说,该消息被送到4开出4,尽管我们已经从我们的手机中删除我们的应用程序。现在,我们尝试发送给所有注册≈1100令牌与此code。
邮件发送,输出是该消息被送到了588的1194
我们没有收到通知我们!
这是什么意思?

During development, when only our own tokens were registered, it always said "The message was delivered to 4 out of 4", even though we had deleted our apps from our phones. Now we tried to send to all ≈1100 registered tokens with this code. The message was sent, and the output was "The message was delivered to 588 out of 1194." And we did not receive the notification ourselves! What does that mean?

大约5分钟后,我换了tokenArray使用数组只包含我自己的令牌,发出了新的推动,我收到一个我的手机上。我也知道一个事实,即在previoustokenArray'的失败(我检查)。

After about 5 minutes, I switched out the tokenArray with an array only containing my own tokens and sent a new push, and I received that one on my phone. I also know for a fact that the 'working' token exist in the previous 'tokenArray' which failed(I checked).

时的推送通知机会游戏!?这是什么意思时,如果($结果)不成?还有,为什么它不能超过500次?

Is push notification a game of chance!? What does it mean when if($result) fails? And why did it fail over 500 times?

证书和质子交换膜或.p12等都是工作,我的确从push1到push2唯一不同的是使用另一个表,它是由我的SQL服务器原始表的克隆。表2只有我的令牌,和它的工作。没有其他的变化作出。只有 SELECT标记与从Tokens2 ,后来我证明了 Tokens2 所有令牌存在令牌
我不知道如果任何人有推可言,或者如果仍然安装了应用程序收到了1200的幸运588

The certificates and .pem and .p12 etc are all working, the only thing I did different from push1 to push2 was to use another table which is a clone from the original table in my SQL-server. Table2 only have my tokens, and it worked. No other changes was made. Only SELECT Token FROM Tokens2, and later I proved that all the tokens in Tokens2 exist in Tokens I have no idea if anyone got the push at all, or if the 'lucky' 588 of the 1200 that still has the app installed received it.

是什么原因造成的?我们不敢发的情况下,一半的另一个已经收到了吧..有一些限制我的速度有多快可以一次发送推?或者什么是我们做错了什么?
请帮忙,谢谢。

What causes this? We don't dare send another one in case half of them already received it.. Is there some limit to how fast I can send pushes at once? Or what are we doing wrong?! Please help, thanks.

推荐答案

您的主循环没有考虑到案件中,苹果公司将关闭套接字连接。正如叶兰提到的,如果你发送一个无效的令牌,苹果公司将关闭在该点的连接,任何进一步的写入fwrite的使用将失败。所以,如果你的589次令牌是无效的,没有其他的推将被发送到苹果公司。

Your main loop does not take into account cases in which Apple will close socket connections. As mentioned by Eran, if you send an invalid token, Apple closes the connection at which point, any further writes using fwrite will fail. So if your 589th token is invalid, no other push will be sent to Apple.

下面是对于那个适合你的逻辑简单的解决;这部分替换主循环if语句:

Here's a simple fix for that that fits into your logic; this part replaces the if statement in the main loop:

if ($result) {
    $i++;
} else {
    fclose($fp);
    // Add code here to re-open socket-connection with Apple.
}

除了由伊兰提到的增强通知格式,还可以使用APNS反馈API查询苹果无效标记并从数据库中清除它们。你可以找到更多的信息来源上,在这里: http://bit.ly/14RPux4

有没有限制多少推送通知,你可以一次发送。我在几秒钟内发送数以千计。唯一真正的限制是你和APNS服务器之间的连接。

There is no limit to how many push notifications you can send at once. I've sent thousands in a few seconds. The only real limitation is the connection between you and the APNS servers.

这篇关于从我们的服务器发送推送通知时胜负的关键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆