APNS - 无法使用Java通知发送到iOS设备 [英] APNS - Can't send notification to iOS device using Java

查看:1864
本文介绍了APNS - 无法使用Java通知发送到iOS设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要得到这个工作,但我完全没办法了......任何帮助将大大AP preciated。

I need to get this working but I'm completely out of options...any help would be greatly appreciated.

我试图发送使用Java通知我的iOS设备,并遵循很多教程和论坛帖子,主要就是这些:的 raywenderlich.com ,的 JavaPNS Basic范例和下图所示的Java的APNS例子。

I'm trying to send notifications to my iOS device using Java and have followed many tutorials and forum posts, mainly these: raywenderlich.com, JavaPNS Basic Example, and the java-apns example shown below.

我是,但是,能够发送使用PHP的通知。有人能看到什么我做错了吗?我已经工作了几天就这个问题和无法弄清楚是什么问题二/三我已经复制的确切code,其他人声称的作品。这里是我的code:

I am, however, able to send notifications using PHP. Can someone see anything I'm doing wrong? I've been working for several days on this and can't figure out what the issue is b/c I've copied the exact code that other people claim works. Here's my code:

public static void main(String[] args) {
    try {
        // Not my real token
        String token = "2919333333333545F19B427AE7E98307B1B2AA9390A38BC0E533E77E11111111";
        ApnsService service = APNS.newService()
                .withCert("C://code//Dev.p12", "password")  // (path to cert, password)
                .withSandboxDestination()
                //.withProductionDestination()
                .build();

        //System.out.println("Testing the connection...");
        //service.testConnection();
        //System.out.println("...Successful!");

        String payload = APNS.newPayload()
                .alertBody("Java test message!")
                .sound("default")
                .build();

        System.out.println("About to send the message...");
        service.push(token, payload);
        System.out.println("...message sent!");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

下面是例外,我得到:

About to send the message...
com.notnoop.exceptions.NetworkIOException: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at com.notnoop.apns.internal.Utilities.wrapAndThrowAsRuntimeException(Utilities.java:284)
at com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:342)
at com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:312)
at com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:46)
at com.notnoop.apns.internal.AbstractApnsService.push(AbstractApnsService.java:56)
at com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:36)
at com.notnoop.apns.internal.AbstractApnsService.push(AbstractApnsService.java:45)
at utilities.APNSTestUtility.main(APNSTestUtility.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:992)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:747)
at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:123)
at java.io.OutputStream.write(OutputStream.java:75)
at com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:328)
... 11 more
Caused by: java.io.EOFException: SSL peer shut down incorrectly
at sun.security.ssl.InputRecord.read(InputRecord.java:505)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
... 16 more

当我有一个错误的密码,我得到的密码不正确的异常,所以我知道它找到.p12文件。我可以发送通知的PHP例子,我在网上找到的,但一定有什么东西我与Java code失踪。我试图在Java-APNS库(如上图所示)和JavaPNS库,我也得到了相同的结果。

When I include a wrong password I get an exception for an incorrect password so I know it's finding the .p12 file. I can send notifications with the PHP example I found online but there MUST be something I'm missing with the Java code. I have tried both the java-apns library (shown above) and the JavaPNS library and I get the same results.

推荐答案

我们不应该用私钥P12文件,而不是我们应该生成您的私钥的P12和Apple的证书下载。
执行以下命令的OpenSSL以获得正确的P12文件:

We should not use the private key p12 file, instead we should generate a p12 from your private key and the cert download from Apple. execute the following OpenSSL command to get the correct p12 file:

developer_identity.cer <= download from Apple
mykey.p12 <= Your private key

openssl x509 -in developer_identity.cer -inform DER -out developer_identity.pem -outform PEM
openssl pkcs12 -nocerts -in mykey.p12 -out mykey.pem
openssl pkcs12 -export -inkey mykey.pem -in developer_identity.pem -out iphone_dev.p12

这篇关于APNS - 无法使用Java通知发送到iOS设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆