Skip to content

Instantly share code, notes, and snippets.

@matzew
Last active March 28, 2017 15:42
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/6c5c047681f7f13df5124090fcd297be to your computer and use it in GitHub Desktop.
Save matzew/6c5c047681f7f13df5124090fcd297be to your computer and use it in GitHub Desktop.
final List<String> tokens = Arrays.asList(
"123",
"456"
);
final ApnsClient apnsClient;
{
try {
apnsClient =new ApnsClientBuilder()
.setClientCredentials(new File("/home/Matthias/jajajaj.p12"), "jaja ja")
.build();
} catch (Exception e) {
e.printStackTrace();
return;
}
}
final Future<Void> connectFuture = apnsClient.connect(ApnsClient.DEVELOPMENT_APNS_HOST);
connectFuture.addListener(new GenericFutureListener<Future<? super Void>>() {
@Override
public void operationComplete(Future<? super Void> future) throws Exception {
if (future.isSuccess() && apnsClient.isConnected()) {
LOGGER.info("Sending stuff");
for (final String token: tokens) {
final SimpleApnsPushNotification pushNotification = createNotification(token, "Here is iteration: " + token);
final Future<PushNotificationResponse<SimpleApnsPushNotification>> sendNotificationFuture = apnsClient.sendNotification(pushNotification);
sendNotificationFuture.addListener(new GenericFutureListener<Future<? super PushNotificationResponse<SimpleApnsPushNotification>>>() {
@Override
public void operationComplete(Future<? super PushNotificationResponse<SimpleApnsPushNotification>> pushNotificationFutue) throws Exception {
if (pushNotificationFutue.isSuccess()) {
final PushNotificationResponse<SimpleApnsPushNotification> pushNotificationResponse =
sendNotificationFuture.get();
if (pushNotificationResponse.isAccepted()) {
LOGGER.info("Push notification accepted by APNs gateway." + pushNotificationResponse);
} else {
LOGGER.info("NOPE: " + pushNotificationResponse);
}
}
}
});
}
LOGGER.warning("here we go....");
final Future<Void> disconnectFuture = apnsClient.disconnect();
disconnectFuture.addListener(new GenericFutureListener<Future<? super Void>>() {
@Override
public void operationComplete(Future<? super Void> future) throws Exception {
if(future.isSuccess()) {
LOGGER.info("AM I connected ? " + apnsClient.isConnected());
}
}
});
}
}
});
LOGGER.info("moving on, while the sending happens...");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment