Hello,everyone!
I have a problem about DNS when i send notifictions,this error alway comes up,but not every time:
This is my code:
public void sendIOSListcast(List<String> deviceTokens, String text) throws NoSuchAlgorithmException, InvalidKeyException, IOException {
if (apnsClient == null) {
apnsClient = new ApnsClientBuilder().setApnsServer(ConstantImServerManage.APNS_HOST)
.setSigningKey(ApnsSigningKey.loadFromPkcs8File(new File(ConstantImServerManage.PATHNAME), ConstantImServerManage.TEAMID, ConstantImServerManage.KEYID)).build();
}
List<String> deviceTokensOfIOS = deviceTokens.stream().filter(o -> !PushConfig.fun(o)).collect(Collectors.toList());
for (int i = 0; i < deviceTokensOfIOS.size(); i++) {
final SimpleApnsPushNotification pushNotification;
final ApnsPayloadBuilder payloadBuilder = new SimpleApnsPayloadBuilder();
payloadBuilder.addCustomProperty("message", text);
payloadBuilder.setContentAvailable(true);
final String payload = payloadBuilder.build();
final String token = TokenUtil.sanitizeTokenString(deviceTokensOfIOS.get(i));
pushNotification = new SimpleApnsPushNotification(token, ConstantImServerManage.TOPIC, payload);
try {
final PushNotificationFuture<SimpleApnsPushNotification, PushNotificationResponse<SimpleApnsPushNotification>>
sendNotificationFuture = apnsClient.sendNotification(pushNotification);
final PushNotificationResponse<SimpleApnsPushNotification> pushNotificationResponse = sendNotificationFuture.get();
if (pushNotificationResponse.isAccepted()) {
System.out.println("IOS Push notification accepted by APNs gateway. " + deviceTokensOfIOS.get(i));
} else {
System.out.println("IOS Notification rejected by the APNs gateway: " + pushNotificationResponse.getRejectionReason() + " " + deviceTokensOfIOS.get(i));
pushNotificationResponse.getTokenInvalidationTimestamp().ifPresent(timestamp -> System.out.println("\t…and the token is invalid as of " + timestamp));
}
} catch (final ExecutionException | InterruptedException e) {
System.out.println("IOS Failed to send push notification.");
}
}
}