2
在Android中成功完成推送通知。现在处理ios推送通知。在APNS服务器中知道未注册令牌的方法(使用Spring Server)
在gcm
严重推送通知的情况下,服务器通知令牌未注册或无效等。同样,有任何方法获取apns
服务器。
请我为发送推送通知代码APNS
public void pushMessage() {
ApnsService service = null;
try {
// get the certificate
InputStream certStream = this.getClass().getClassLoader().getResourceAsStream("your_certificate.p12");
service = APNS.newService().withCert(certStream, "your_cert_password").withSandboxDestination().build();
// or
// service = APNS.newService().withCert(certStream,
// "your_cert_password").withProductionDestination().build();
service.start();
// read your user list
List<User> userList = userDao.readUsers();
for (User user : userList) {
try {
// we had a daily update here, so we need to know how many
//days the user hasn't started the app
// so that we get the number of updates to display it as the badge.
int days = (int) ((System.currentTimeMillis() - user.getLastUpdate())/1000/60/60/24);
PayloadBuilder payloadBuilder = APNS.newPayload();
payloadBuilder = payloadBuilder.badge(days).alertBody("some message you want to send here");
// check if the message is too long (it won't be sent if it is)
//and trim it if it is.
if (payloadBuilder.isTooLong()) {
payloadBuilder = payloadBuilder.shrinkBody();
}
String payload = payloadBuilder.build();
String token = user.getToken();
service.push(token, payload);
} catch (Exception ex) {
// some logging stuff
}
}
} catch (Exception ex) {
// more logging
} finally {
// check if the service was successfull initialized and stop it here, if it was
if (service != null) {
service.stop();
}
}
}
我用com.notnoop.apns
库发送APNS
推送通知。
嗨Ajmal,需要你的输入从Java Spring连接APNS服务器...你能分享我的任何初学者教程吗? –