Skip to content

Instantly share code, notes, and snippets.

@matzew
Last active March 24, 2017 09:59
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/a8f030e9e83798bff22675ef57175538 to your computer and use it in GitHub Desktop.
Save matzew/a8f030e9e83798bff22675ef57175538 to your computer and use it in GitHub Desktop.
for (final String token: tokens) {
final SimpleApnsPushNotification pushNotification = createNotification(token, "Here is iteration: " + token);
final Future<PushNotificationResponse<SimpleApnsPushNotification>> sendNotificationFuture = apnsClient.sendNotification(pushNotification);
try {
final PushNotificationResponse<SimpleApnsPushNotification> pushNotificationResponse =
sendNotificationFuture.get();
if (pushNotificationResponse.isAccepted()) {
System.out.println("Push notification accepted by APNs gateway." + pushNotificationResponse);
} else {
System.out.println("Notification rejected by the APNs gateway: " +
pushNotificationResponse.getRejectionReason());
if (pushNotificationResponse.getTokenInvalidationTimestamp() != null) {
System.out.println("\t…and the token is invalid as of " +
pushNotificationResponse.getTokenInvalidationTimestamp());
}
}
} catch (final ExecutionException e) {
System.err.println("Failed to send push notification.");
e.printStackTrace();
if (e.getCause() instanceof ClientNotConnectedException) {
System.out.println("Waiting for client to reconnect…");
apnsClient.getReconnectionFuture().await();
System.out.println("Reconnected.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment