推送通知到IOS问题CodeName One

时间:2016-01-25 10:14:06

标签: java ios push-notification apple-push-notifications codenameone

我尝试将通知从java服务器推送到IOS客户端 我有这个错误(来自代号为一个服务器的响应)

{“error”:“无法向APNS发送推送:com.notnoop.exceptions.NetworkIOException:javax.net.ssl.SSLHandshakeException:握手时远程主机已关闭连接”}

    String GOOGLE_SERVER_KEY = "********************************************";
    HttpsURLConnection connection;
    String url = "https://push.codenameone.com/push/push"; 
    String TOKEN = "******-****-*****-*****-**************";
    String URL_ENCODED_LINK_TO_YOUR_P12_FILE =
        "https://dl.dropboxusercontent.com/*/******************/Certificates.p12";
    String URL_ENCODED_CERTIFICATE_PASSWORD = "******";

    String deviceId =
        "cn1-gcm-*******************************************************";
    String deviceId2 =
        "cn1-ios-***************************************************";
    String MESSAGE_BODY = "This notification  message coming from server";
    try {

        connection = (HttpsURLConnection)new URL(url).openConnection();
        connection.setDoOutput(true);
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
        String query =
            "token=" + TOKEN + "&device=" + deviceId + "&device=" +
            deviceId2 + "&type=1&auth=" + GOOGLE_SERVER_KEY +
            "&certPassword=" + URL_ENCODED_CERTIFICATE_PASSWORD +
            "&cert=" + URL_ENCODED_LINK_TO_YOUR_P12_FILE + "&body=" +
            URLEncoder.encode(MESSAGE_BODY, "UTF-8") + "&production=false";
        try {
            OutputStream output = connection.getOutputStream();
            output.write(query.getBytes("UTF-8"));
        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println("ResponseCode : " + connection.getResponseCode());
        System.out.println("ResponsenMessage : " +
                           connection.getResponseMessage());
        BufferedReader br =new BufferedReader(new InputStreamReader((connection.getInputStream())));

        String output;
        String result = "";
        System.out.println("Output  .... \n");
        while ((output = br.readLine()) != null) {
            System.out.println(output);
            result += output + "\n";
        }

        connection.disconnect();
    } catch (Exception e) {
        e.printStackTrace();
    }

来自代号为一个服务器的输出

回复代码:200

回复讯息:好的

输出......

{“error”:“无法向APNS发送推送:com.notnoop.exceptions.NetworkIOException:javax.net.ssl.SSLHandshakeException:握手期间远程主机关闭连接”}

2 个答案:

答案 0 :(得分:1)

握手异常通常意味着Codename One服务器由于安全问题而无法连接。这可能意味着您的P12不正确。

您确定使用的是正确的P12文件吗?请记住,有2个推送证书(不要与2个签名证书混淆),根据沙箱标志的值,只应使用其中一个。

您是否使用过证书向导?

答案 1 :(得分:0)

我认为在服务器端或客户端都禁用了2195和2196个端口,需要启用苹果推送通知。