我需要這個工作,但我完全沒有選擇...任何幫助將不勝感激。APNS - 無法使用Java發送通知到iOS設備
我試圖使用Java將通知發送到我的iOS設備,並且遵循了很多教程和論壇帖子,主要有:raywenderlich.com,JavaPNS Basic Example以及下面顯示的java-apns示例。
但是,我可以使用PHP發送通知。有人可以看到我做錯了什麼嗎?我已經在這工作了好幾天,並且無法弄清楚問題在哪裏。我已經複製了其他人聲稱的確切代碼。這裏是我的代碼:
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代碼丟失某些內容。我已經嘗試了java-apns庫(如上所示)和JavaPNS庫,並獲得了相同的結果。
看,如果這能幫助你https://stackoverflow.com/questions/12585858/cannot-send-push-notifications-using-javapns-javaapns -ssl-handshake-failure –
哇,我無法相信它!你是否想發佈回覆,以便將其標記爲正確答案?非常感謝!!!!!! – pluffmud