diff --git a/src/main/java/com/notnoop/apns/DeliveryError.java b/src/main/java/com/notnoop/apns/DeliveryError.java index 41f9cd01..ae036bd9 100644 --- a/src/main/java/com/notnoop/apns/DeliveryError.java +++ b/src/main/java/com/notnoop/apns/DeliveryError.java @@ -49,6 +49,7 @@ public enum DeliveryError { INVALID_TOPIC_SIZE(6), INVALID_PAYLOAD_SIZE(7), INVALID_TOKEN(8), + SHUTDOWN(10), NONE(255), UNKNOWN(254); diff --git a/src/main/java/com/notnoop/apns/internal/ApnsConnectionImpl.java b/src/main/java/com/notnoop/apns/internal/ApnsConnectionImpl.java index b7a36397..4688a9fa 100644 --- a/src/main/java/com/notnoop/apns/internal/ApnsConnectionImpl.java +++ b/src/main/java/com/notnoop/apns/internal/ApnsConnectionImpl.java @@ -157,7 +157,9 @@ public void run() { Utilities.close(socket); int command = bytes[0] & 0xFF; - if (command != 8) { + // A status code of 10 indicates that the APNs server closed the connection, + // The notification identifier in the error response indicates the last notification that was successfully sent. + if (command != 8 && command != 10) { throw new IOException("Unexpected command byte " + command); } int statusCode = bytes[1] & 0xFF; @@ -185,8 +187,10 @@ public void run() { } if (foundNotification) { - logger.debug("delegate.messageSendFailed, message id {}", notification.getIdentifier()); - delegate.messageSendFailed(notification, new ApnsDeliveryErrorException(e)); + if (DeliveryError.INVALID_TOKEN == e) { + logger.debug("delegate.messageSendFailed, message id {}", notification.getIdentifier()); + delegate.messageSendFailed(notification, new ApnsDeliveryErrorException(e)); + } } else { cachedNotifications.addAll(tempCache); int resendSize = tempCache.size(); @@ -195,8 +199,11 @@ public void run() { cacheLength = cacheLength + (resendSize / 2); delegate.cacheLengthExceeded(cacheLength); } - logger.debug("delegate.messageSendFailed, unknown id"); - delegate.messageSendFailed(null, new ApnsDeliveryErrorException(e)); + + if (DeliveryError.INVALID_TOKEN == e) { + logger.debug("delegate.messageSendFailed, unknown id"); + delegate.messageSendFailed(null, new ApnsDeliveryErrorException(e)); + } } int resendSize = 0;