由于handshake_failure,IOS推送通知失败

时间:2013-12-20 13:00:53

标签: java java-ee apple-push-notifications

iOS push notification由于handshake_failure而失败,但它在我的本地计算机上工作正常,并且在服务器上部署时出错。

我正在使用apns-0.1.5.jar

代码:

    static
    {
       service = APNS.newService()
            .withCert(ClassLoader.class.getResourceAsStream("cert.p12"), "pwd")
            .withSandboxDestination()
            .build();
    }


    public static void pushMSG(String msg,String deviceToken)
    {

      String payload = APNS.newPayload().alertBody(msg).build();

      AppLog.info("Message : "+msg+", deviceToken "+deviceToken);

      service.push(deviceToken, payload);

    }

错误日志

    com.notnoop.exceptions.NetworkIOException: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
com.notnoop.apns.internal.Utilities.wrapAndThrowAsRuntimeException(Utilities.java:268)
com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:173)
com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:46)
com.notnoop.apns.internal.AbstractApnsService.push(AbstractApnsService.java:52)
com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:36)
com.gcash.notification.APNSManager.pushMSG(APNSManager.java:35)
com.gcash.TestServlet.doGet(TestServlet.java:58)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    root cause

    javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:136)
com.sun.net.ssl.internal.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1720)
com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:954)
com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1138)
com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:632)

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,我通过以下步骤解决了这个问题。

  1. 检查.p12文件和.cer文件。确保它们彼此对应。
  2. 您是否导出.p12文件并直接在代码中使用?如果是,请参阅此answer。 “我们应该从您的私钥和Apple的证书下载中生成一个p12。”
  3. 希望它有效。