使用Javapns的Apple推送通知服务

时间:2012-12-18 13:26:39

标签: java ios apple-push-notifications

我正在使用以下代码向Apple Notification Server发送通知。

import javapns.Push;
import javapns.communication.exceptions.CommunicationException;
import javapns.communication.exceptions.KeystoreException;

public class APN 
{
   public static void main(String[] args) {
        try {
            Push.alert("Hello World!", "keystore.p12", "mypassword", false, "myDeviceIdentifier");
        } 
        catch (CommunicationException e) {
           e.printStackTrace();
        } 
        catch (KeystoreException e) {
            e.printStackTrace();
        }
   }
}

我已经包含了Javapns文档中指定的所有罐子 但是,当我执行此代码时,它会抛出以下异常。

log4j:WARN No appenders could be found for logger (javapns.notification.Payload).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
javapns.communication.exceptions.CommunicationException: Communication exception:
java.net.ConnectException: Operation timed out
at javapns.communication.ConnectionToAppleServer.getSSLSocket(ConnectionToAppleServer.java:158)
at javapns.notification.PushNotificationManager.initializeConnection(PushNotificationManager.java:106)
at javapns.Push.sendPayload(Push.java:171)
at javapns.Push.alert(Push.java:47)
at com.mydomain.myapp.APN.main(APN.java:12)
Caused by: java.net.ConnectException: Operation timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:432)
at java.net.Socket.connect(Socket.java:529)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:570)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.<init>(SSLSocketImpl.java:371)
at com.sun.net.ssl.internal.ssl.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:71)
at javapns.communication.ConnectionToAppleServer.getSSLSocket(ConnectionToAppleServer.java:155)
... 4 more

我已经创建了.p12证书,我的设备标识符长度为64个字。

请告诉我解决方案。
任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:3)

关键信息是:

java.net.ConnectException:操作超时

您确定运行此代码的服务器可以连接到您指定的端口上的apple apn服务器吗?

提示:使用telnet验证。