I use the PUSHY library 0.15.2 version to send push notifications to ios devices using Spring boot.
The APNS code look like this -
ApnsClientBuilder clientBuilder = new ApnsClientBuilder();
clientBuilder.setApnsServer(ApnsClientBuilder.DEVELOPMENT_APNS_HOST);
clientBuilder.setConnectionTimeout(Duration.ofMillis(60000));
File file = new File(getClass().getClassLoader().getResource("zzzzz").getFile());
clientBuilder.setClientCredentials(file, "yyyyy");
apnsClient = clientBuilder.build();
ApnsPayloadBuilder payloadBuilder = new SimpleApnsPayloadBuilder();
payloadBuilder.setAlertTitle("xxxx");
payloadBuilder.setAlertBody("This is test message");
SimpleApnsPushNotification pushNotification = new SimpleApnsPushNotification(messageDto.getDeviceId(),
"com.np.gotprint", payloadBuilder.build());
apnsClient.sendNotification(pushNotification).get();
System.out.println("send successfully");
but I am getting the following error -
Caused by: io.netty.channel.AbstractChannel$AnnotatedSocketException: Network is unreachable: api.sandbox.push.apple.com/2620:149:208:304:0:0:0:1f:443
Caused by: java.net.SocketException: Network is unreachable
at sun.nio.ch.Net.connect0(Native Method)
at sun.nio.ch.Net.connect(Net.java:454)
at sun.nio.ch.Net.connect(Net.java:446)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:648)
at io.netty.util.internal.SocketUtils$3.run(SocketUtils.java:83)
at io.netty.util.internal.SocketUtils$3.run(SocketUtils.java:80)
at java.security.AccessController.doPrivileged(Native Method)
at io.netty.util.internal.SocketUtils.connect(SocketUtils.java:80)
Note - When I run the code locally, it works fine, throws an error when I deploy in staging env.
Am I doing something wrong here?
Based on the exception you get
"Network is unreachable: api.sandbox.push.apple.com/2620:149:208:304:0:0:0:1f:443",
it seems that you are attempting to use IPv6 but your network does not support it. You may force IPv4 preference with the following system property.