7

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?

Thanks in advance,

UPDATED SOLUTION:

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;
}
5
  • APN service has limit , you only can send 256 byts of data each time, Jul 17, 2013 at 12:34
  • @kirtiavaiya yes, I know that and I check it before sending the message, so that it is not the problem. Jul 17, 2013 at 12:42
  • I think if you are sending data package(payload) with right format and size then it's a issue related to sending data to APNS via looping through receivers list. .
    – 120hit
    Jul 17, 2013 at 12:49
  • @mrm_arrasate This is a good read for troubleshooting push notifications.
    – Amar
    Jul 17, 2013 at 13:12
  • stream_set_blocking($fp, 0) maybe not work with tls
    – Thao Ngo
    Jun 16, 2015 at 4:56

3 Answers 3

11

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.

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.

3
  • I have checked the response from Apple and in all cases it returns the apns message size. Also, I have checked the feedback service and it returns empty Jul 18, 2013 at 7:39
  • you are right, I was sending push to invalid tokens, but I didn't check the apple response correctly, now it works perfect. Thanks!! This link helped me learn-php-by-example.blogspot.com.es/2013/01/…, with "checkAppleErrorResponse" function. Jul 18, 2013 at 10:30
  • @Eran I tried to use the same code above, and it gave me the invalid tokens which are development tokens, and I removed them from database, but still not received by all devices, and I gave up :(
    – Fatima
    Dec 19, 2013 at 12:52
0

There is no limit on the number of users you can send to, you just have to make sure that the size of the message you send it below that limit, which as Kirti stated, is around 2048 bytes.

There is also no limit to how frequently you can send messages, but I would not recommend sending things too often.

2
  • I'm sending the same notification to all users (some message), and some of them receive the notifications and others no, so I guess that the length is not the problem, anyway, I am checking the limit. Jul 17, 2013 at 12:56
  • Are you sure each send succeeds or are you being blocked by your ISP for what may be perceived as spamming or something like that? Jul 17, 2013 at 12:57
0

Might want to check this out:

There are no caps or batch size limits for using APNs. The iOS 6.1 press release stated that APNs has sent over 4 trillion push notifications since it was established. It was announced at WWDC 2012 that APNs is sending 7 billion notifications daily.

If you're seeing throughput lower than 9,000 notifications per second, your server might benefit from improved error handling logic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.