ApnsService service = APNS.newService() .withCert("/etc/Certificates.p12", "password") .withSandboxDestination() // or .withProductionDestination() .build(); String payload = APNS.newPayload() .alertBody("My alert message") .badge(45) .sound("default") .build(); String deviceToken = "f4201f5d8278fe39545349d0868a24a3b60ed732"; log.warn("Sending push notification..."); service.push(deviceToken, payload);
final InputStream certificate = Thread.currentThread().getContextClassLoader() .getResourceAsStream("aps_dev_credentials.p12"); final char[] passwd = {'1','2','3','4'}; final ApnsService apnsService = com.notnoop.apns.APNS.newService() .withCert(certificate, new String(passwd)) .withSandboxDestination().build(); apnsService.testConnection();
ApnsService service = null; service = APNS.newService() .withCert(certificatePath, certificatePassword) .withProductionDestination() .asPool(threadCount) .build(); service.start();
@Override public String toString() { return build(); }
PayloadBuilder payloadBuilder = APNS.newPayload(); payloadBuilder = payloadBuilder .alertBody("yourMessage") .sound("default"));
/** * Returns the length of payload bytes once marshaled to bytes * * @return the length of the payload */ public int length() { return copy().buildBytes().length; }
/** * Returns a copy of this builder * * @return a copy of this builder */ public PayloadBuilder copy() { return new PayloadBuilder(root, aps, customAlert); }
/** * Construct service which will process notification requests in batch. * After each request batch will wait <code>waitTimeInSec (set as 5sec)</code> for more request to come * before executing but not more than <code>maxWaitTimeInSec (set as 10sec)</code> * * Note: It is not recommended to use pooled connection */ public ApnsServiceBuilder asBatched() { return asBatched(5, 10); }
/** * 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); }
/** * Returns a new APNS Service for sending iPhone notifications */ public static ApnsServiceBuilder newService() { return new ApnsServiceBuilder(); } }
/** * Specify the reconnection policy for the socket connection. * * Note: This option has no effect when using non-blocking * connections. */ public ApnsServiceBuilder withReconnectPolicy(ReconnectPolicy.Provided rp) { this.reconnectPolicy = rp.newObject(); return this; }
private void configureApnsDelegate(ApnsServiceBuilder builder) { if (apnsDelegate != null) { builder.withDelegate(apnsDelegate); } }
/** * 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); }
/** * Returns the length of the message in bytes as it is encoded on the wire. * * Apple require the message to be of length 255 bytes or less. * * @return length of encoded message in bytes */ public int length() { int length = 1 + 4 + 4 + 2 + deviceToken.length + 2 + payload.length; assert marshall().length == length; return length; }
/** * Returns the length of the message in bytes as it is encoded on the wire. * * Apple require the message to be of length 255 bytes or less. * * @return length of encoded message in bytes */ public int length() { int length = 1 + 2 + deviceToken.length + 2 + payload.length; assert marshall().length == length; return length; }
/** * Returns true if the payload built so far is larger than * the size permitted by Apple (which is 256 bytes). * * @return true if the result payload is too long */ public boolean isTooLong() { return length() > Utilities.MAX_PAYLOAD_LENGTH; }
PayloadBuilder payload = APNS.newPayload(); // build your payload if (payload.isTooLong()) { // your payload is too long, a push() will result in the above exception }
/** * 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(); } }