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服務器...你能分享我的任何初學者教程嗎? –