我正在使用javapns 2.2来发送推送通知并从中获得成功的响应,但通知未显示在我的iOS测试手机上。我已经创建了一个使用wiki中的代码的单元测试:
@Test
public void shouldSendATestMessageNotifyingDeviceThatNewMessageIsReady()
throws RepositoryException {
NotificationService nService = new NotificationService();
nService.sendNotification("incoming message",
"4854862ec7b58a939538f2e1262a48a7e8a3331c5f0e11feb11e1a79ff764649");
}
public void sendNotification(String message, String deviceId) {
try {
List<PushedNotification> notifications = Push.alert(message, certLocation, certPassword, false,
deviceId);
for (PushedNotification notification : notifications) {
if (notification.isSuccessful()) {
/* Apple accepted the notification and should deliver it */
System.out.println("Push notification sent successfully to: " +
notification.getDevice().getToken());
/* Still need to query the Feedback Service regularly */
} else {
String invalidToken = notification.getDevice().getToken();
/* Add code here to remove invalidToken from your database */
/* Find out more about what the problem was */
Exception theProblem = notification.getException();
theProblem.printStackTrace();
/* If the problem was an error-response packet returned by Apple, get it */
ResponsePacket theErrorResponse = notification.getResponse();
if (theErrorResponse != null) {
System.out.println(theErrorResponse.getMessage());
}
}
}
} catch (CommunicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (KeystoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我正在使用我在钥匙串中创建的生产推送SSL证书(p12)。我在我的iOS设备上有一个adhoc版本,我从我的iOS应用程序中的NSLog
代码中提取了我传入此测试的设备ID,用于我正在测试的设备,因此它是有效的。
我用dev证书替换了我的prod证书,并得到了无效的令牌错误,因为我希望确保它找到该文件。
由于javapns告诉我推送的消息已成功发送,因此不确定还有什么可看。想法?