/** * Shrinks the alert message body so that the resulting payload * message fits within require Apple specification (256 bytes). * * This method performs best-effort approach, and its behavior * is unspecified when handling alerts where the payload * without body is already longer than the permitted size, or * if the break occurs within word. * * @return this */ public PayloadBuilder shrinkBody() { return shrinkBody(""); }
for (ApnsDevice apnsDevice : apnsDeviceList) { try { PayloadBuilder perDevicePayloadBuilder = payloadBuilder.copy() .badge(apnsDevice.getBadgeCount()+1); // check if the message is too long (it won't be sent if it is) //and trim it if it is. if (perDevicePayloadBuilder.isTooLong()) { logger.warn("Payload is too long, shrinking it"); perDevicePayloadBuilder = perDevicePayloadBuilder.shrinkBody(); } String token = apnsDevice.getDeviceToken(); service.push(token, perDevicePayloadBuilder.build()); } catch (Exception ex) { logger.error("Error while pushing apns alerts", ex); } }