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();
PayloadBuilder payloadBuilder = APNS.newPayload(); payloadBuilder = payloadBuilder .alertBody("yourMessage") .sound("default"));
/** * Returns a copy of this builder * * @return a copy of this builder */ public PayloadBuilder copy() { return new PayloadBuilder(root, aps, customAlert); }
/** * Returns the length of payload bytes once marshaled to bytes * * @return the length of the payload */ public int length() { return copy().buildBytes().length; }
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); } }
@Override public String toString() { return build(); }
/** * 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(""); }
/** * Requests clearing of the badge number next to the application * icon. * * This is an alias to {@code badge(0)}. * * @return this */ public PayloadBuilder clearBadge() { return badge(0); }
/** * Set the notification view to display an action button. * * This is an alias to {@code actionKey(null)} * * @return this */ public PayloadBuilder noActionButton() { return actionKey(null); }
public PayloadBuilder mdm(final String s) { return customField("mdm", s); }
/** * 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()); }
/** * Returns a new Payload builder */ public static PayloadBuilder newPayload() { return new PayloadBuilder(); }
/** * @return a new instance of Payload Builder */ public static PayloadBuilder newPayload() { return new PayloadBuilder(); } }