Last active
March 24, 2017 09:59
-
-
Save matzew/a8f030e9e83798bff22675ef57175538 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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