@Override public String toString() { return build(); }
/** * Returns the bytes representation of the payload according to * Apple APNS specification * * @return the bytes as expected by Apple */ public byte[] buildBytes() { return Utilities.toUTF8Bytes(build()); }
PayloadBuilder payloadBuilder = APNS.newPayload() .alertBody(message) .sound(sound) .actionKey(actionLocKey) .localizedKey(locKey) .localizedArguments(locArgs) .badge(badge) .customFields(customData) .category(category); if (contentAvailable!=null && contentAvailable.intValue()==1){ payloadBuilder.instantDeliveryOrSilentNotification(); } payload =payloadBuilder.build();
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); } }
private void constructNotificationAndNotify(Exchange exchange, MessageType messageType) { String payload; Collection<String> tokens; if (isTokensConfiguredUsingUri()) { if (hasTokensHeader(exchange)) { throw new IllegalArgumentException("Tokens already configured on endpoint " + ApnsConstants.HEADER_TOKENS); } tokens = new ArrayList<>(tokenList); } else { String tokensHeader = getHeaderTokens(exchange); tokens = extractTokensFromString(tokensHeader); } if (messageType == MessageType.STRING) { String message = exchange.getIn().getBody(String.class); payload = APNS.newPayload().alertBody(message).build(); } else { String message = exchange.getIn().getBody(String.class); payload = message; } Date expiry = exchange.getIn().getHeader(ApnsConstants.HEADER_EXPIRY, Date.class); if (expiry != null) { getEndpoint().getApnsService().push(tokens, payload, expiry); } else { getEndpoint().getApnsService().push(tokens, payload); } }