adobkin / php-apn

php-apn is a PHP module, to introduce simple yet powerful interface for sending push notifications to iOS and OS X devices from within your PHP code
http://libcapn.org/php-apn
Other
77 stars 16 forks source link

Could not send push, invalid token #7

Closed tanner0101 closed 8 years ago

tanner0101 commented 10 years ago

I have a couple thousand devices I am trying to send a push notification to, and I keep getting this error: message":"Could not send push invalid device token","errno":703 It is sending the push notification to some devices, but stops sending once it hits an invalid token. How can I set PHP-APN to ignore these invalid tokens or how do I get rid of them efficiently?

adobkin commented 10 years ago

You can't, apple closes connection if token is invalid. You should reconnect and resent any notifications you sent after it

seme1 commented 9 years ago

Can you please give an example for how to receover from a closed connection ? In particular, my question is related to the case when sending a single message to a large number of devices.

apn_payload_set_array($payload, array(
      'body' => 'This push was sent using PHP && php-apn',
      'sound' => 'default',
      'badge' => 34,
      'tokens' => array (
          'device1Token',
          'device2Token',
          'device3Token',
          ... // and many more
      )
));
rgomezcasas commented 9 years ago

I'm trying to retrieve the devices invalids tokens

if (apn_feedback_connect($apn, $error, $errcode)) {
    $tokens = apn_feedback($apn, $error, $errcode);
    if ( ! is_array($tokens)) {
        echo 'Failed to obtain device tokens: ' . $error;
    } else {
        foreach($tokens as $token) {
              echo 'Token: '.$token;
        }
    }
} else {
    echo 'Failed to connect to Apple Push Feedback Service: ' . $error;
}

Previously I'm forcing invalid devices tokens but still this is returning me $tokens empty array.

adobkin commented 9 years ago

apn_feedback shan't return invalid tokens. It's return tokens from removed app

The Apple Push Notification service includes a feedback service to give you information about failed remote notifications. When a remote notification cannot be delivered because the intended app does not exist on the device, the feedback service adds that device’s token to its list

rgomezcasas commented 9 years ago

Ahh ok, @adobkin thank you very much!