failed to resolve 'api.sandbox.push.apple.com' after 3 queries?

86 views
Skip to first unread message

xuebin zhao

unread,
Nov 30, 2020, 4:24:01 AM11/30/20
to pushy
Hello,everyone!
I have a problem about DNS when i send notifictions,this error alway comes up,but  not every time:
    java.net.UnknownHostException: failed to resolve 'api.sandbox.push.apple.com' after 3 queries?

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.");
            }
        }
    }

i use command "nslookup api.sandbox.push.apple.com" following result:
 1 (2).png
Reply all
Reply to author
Forward
0 new messages