Apple 推送通知限制 [英] Apple Push Notification Limits

查看:56
本文介绍了Apple 推送通知限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm developing an iOS application that uses push notifications, I have implemented the app and the server side and it works great if I send just one or two notifications. The problem comes when I need to send the same notification to all of my users, the notifications only get to the first users of the loop. I'm in sandbox, so I wonder if there is any limit for sandbox environment, because I have read that the APNS service has no limit. Any idea?

提前致谢,

更新的解决方案:

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

I had to check apple response, I was sending push to invalid tokens and Apple disconnected me from server. With the following function I have solved the problem. Thanks @Eran and 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 服务器的套接字.无效通知之后写入该套接字的所有通知将被丢弃,直到您打开一个新套接字.

The likely problem is that some of the device tokens you are using are invalid (remember that production device tokens are invalid in sandbox environment and vica versa). Sending a notification to an invalid device token will close your socket to the APN servers. All the notifications written to that socket after the invalid one will be discarded until you open a new socket.

您可以尝试阅读 Apple 的错误响应,以找出无效的设备令牌.

You can try to read error responses from Apple to find out which device token is invalid.

您绝对应该阅读技术说明的错误检查部分其他人已经在这里提到过.

You should definitely read the error checking section of the Tech Note that was already mentioned by other people here.

这篇关于Apple 推送通知限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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