Skip to content

Instantly share code, notes, and snippets.

@matzew
Created January 29, 2015 06:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matzew/461fb3f6fb26cfc092e7 to your computer and use it in GitHub Desktop.
Save matzew/461fb3f6fb26cfc092e7 to your computer and use it in GitHub Desktop.
ApnsService service =
APNS.newService()
.withCert("/Users/matzew/Desktop/prod.p12", "ultraSecurePassword")
.withProductionDestination()
.withDelegate(new ApnsDelegate() {
@Override
public void messageSent(ApnsNotification message, boolean resent) {
System.out.println("messageSent ->" + message);
}
@Override
public void messageSendFailed(ApnsNotification message, Throwable e) {
System.out.println("messageSendFailed -> " + Utilities.encodeHex(message.getDeviceToken()) + "\n" +e);
}
@Override
public void connectionClosed(DeliveryError e, int messageIdentifier) {
System.out.println("Closed: " + e);
}
@Override
public void cacheLengthExceeded(int newCacheLength) {
}
@Override
public void notificationsResent(int resendCount) {
System.out.println("Retry: " + resendCount);
}
})
.build();
final String payload = APNS.newPayload().alertBody("Ahoy! It is now \r\n -> "+new Date()).sound("default").build();
service.push(collectionContainingMyTokens, payload);
try {
//Thread.sleep(TimeUnit.SECONDS.toMillis(5));
Thread.currentThread().join();
}
catch (InterruptedException e) {
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment