【问题标题】:Apple Push Notification LimitsApple 推送通知限制
【发布时间】:2013-07-16 00:02:34
【问题描述】:

我正在开发一个使用推送通知的 iOS 应用程序,我已经实现了该应用程序和服务器端,如果我只发送一两个通知,它就可以很好地工作。当我需要向所有用户发送相同的通知时,问题就出现了,通知只会发送给循环的第一个用户。 我在沙箱中,所以我想知道沙箱环境是否有任何限制,因为我读过APNS服务没有限制。 有什么想法吗?

提前致谢,

更新的解决方案:

我必须检查苹果的响应,我正在向无效令牌发送推送,苹果断开了我与服务器的连接。通过以下功能,我解决了这个问题。 谢谢@Eran 和this post

/* FUNCTION to check if there is an error response from Apple
 * Returns TRUE if there was and FALSE if there was not
 */
public function checkAppleErrorResponse($fp) {

    //byte1=always 8, byte2=StatusCode, bytes3,4,5,6=identifier(rowID). 
    // Should return nothing if OK.

    //NOTE: Make sure you set stream_set_blocking($fp, 0) or else fread will pause your script and wait 
    // forever when there is no response to be sent. 
    $apple_error_response = fread($fp, 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';

        }

        echo '<br><b>+ + + + + + ERROR</b> Response Command:<b>' . $error_response['command'] . '</b>&nbsp;&nbsp;&nbsp;Identifier:<b>' . $error_response['identifier'] . '</b>&nbsp;&nbsp;&nbsp;Status:<b>' . $error_response['status_code'] . '</b><br>';

        echo 'Identifier is the rowID (index) in the database that caused the problem, and Apple will disconnect you from server. To continue sending Push Notifications, just start at the next rowID after this Identifier.<br>';
        return true;
    }
    return false;
}

【问题讨论】:

  • APN服务有限制,每次只能发送256字节的数据,
  • @kirtiavaiya 是的,我知道,我在发送消息之前检查了它,所以这不是问题。
  • 我认为如果您发送格式和大小正确的数据包(有效负载),那么这是与通过循环接收器列表向 APNS 发送数据有关的问题。 .
  • @mrm_arrasate 这是troubleshooting push notifications 的好读物。
  • stream_set_blocking($fp, 0) 可能不适用于 tls

标签: ios iphone push-notification apple-push-notifications


【解决方案1】:

可能想check this out:

使用 APN 没有上限或批量大小限制。 iOS 6.1 新闻稿称 APNs 已发送超过 4 万亿次推送 自成立以来的通知。它是在 WWDC 上宣布的 2012 年,APN 每天发送 70 亿条通知。

如果您发现每个通知的吞吐量低于 9,000 个 其次,您的服务器可能会受益于改进的错误处理 逻辑。

【讨论】:

    【解决方案2】:

    您可以发送给的用户数量没有限制,您只需确保发送的消息大小低于该限制,正如 Kirti 所说,大约为 2048 字节。

    您可以发送消息的频率也没有限制,但我不建议发送太频繁。

    【讨论】:

    • 我正在向所有用户发送相同的通知(一些消息),他们中的一些人收到通知而其他人没有,所以我猜长度不是问题,无论如何,我正在检查限制。
    • 您确定每次发送都成功,或者您是否因为可能被视为垃圾邮件或类似内容而被您的 ISP 阻止?
    【解决方案3】:

    可能的问题是您使用的某些设备令牌无效(请记住,生产设备令牌在沙盒环境中无效,反之亦然)。向无效的设备令牌发送通知将关闭您与 APN 服务器的套接字。在无效通知之后写入该套接字的所有通知都将被丢弃,直到您打开一个新套接字。

    您可以尝试阅读来自 Apple 的错误响应,以找出哪个设备令牌无效。

    您绝对应该阅读这里其他人已经提到的Tech Note 的错误检查部分。

    【讨论】:

    • 我已经检查了 Apple 的响应,在所有情况下它都会返回 apns 消息大小。另外,我检查了反馈服务,它返回空
    • 你是对的,我正在向无效令牌发送推送,但我没有正确检查苹果的响应,现在它可以正常工作了。谢谢!!此链接通过“checkAppleErrorResponse”功能帮助了我learn-php-by-example.blogspot.com.es/2013/01/…
    • @Eran 我尝试使用上面相同的代码,它给了我开发令牌的无效令牌,我将它们从数据库中删除,但仍然没有被所有设备接收,我放弃了:(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-15
    • 1970-01-01
    • 2017-11-18
    • 2013-04-27
    相关资源
    最近更新 更多