javapns.notification.PushedNotification Java Examples
The following examples show how to use
javapns.notification.PushedNotification.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Worker.java From io2014-codelabs with Apache License 2.0 | 5 votes |
private void processPushedNotifications(String taskName, PushedNotifications notifications) { List<String> invalidTokens = new ArrayList<String>(); for (PushedNotification notification : notifications) { if (!notification.isSuccessful()) { log.log(Level.WARNING, "Notification to device " + notification.getDevice().getToken() + " from task " + taskName + " wasn't successful.", notification.getException()); // Check if APNS returned an error-response packet. ResponsePacket errorResponse = notification.getResponse(); if (errorResponse != null) { if (errorResponse.getStatus() == 8) { String invalidToken = notification.getDevice().getToken(); invalidTokens.add(invalidToken); } log.warning("Error response packet: " + errorResponse.getMessage()); } } if (invalidTokens.size() > 0) { Utility.enqueueRemovingDeviceTokens(invalidTokens); } } }
Example #2
Source File: Worker.java From solutions-mobile-backend-starter-java with Apache License 2.0 | 5 votes |
private void processPushedNotifications(String taskName, PushedNotifications notifications) { List<String> invalidTokens = new ArrayList<String>(); for (PushedNotification notification : notifications) { if (!notification.isSuccessful()) { log.log(Level.WARNING, "Notification to device " + notification.getDevice().getToken() + " from task " + taskName + " wasn't successful.", notification.getException()); // Check if APNS returned an error-response packet. ResponsePacket errorResponse = notification.getResponse(); if (errorResponse != null) { if (errorResponse.getStatus() == 8) { String invalidToken = notification.getDevice().getToken(); invalidTokens.add(invalidToken); } log.warning("Error response packet: " + errorResponse.getMessage()); } } if (invalidTokens.size() > 0) { Utility.enqueueRemovingDeviceTokens(invalidTokens); } } }
Example #3
Source File: PushNotificationWorker.java From solutions-ios-push-notification-sample-backend-java with Apache License 2.0 | 5 votes |
private void processPushedNotifications(String taskName, PushedNotifications notifications) { List<String> invalidTokens = new ArrayList<String>(); for (PushedNotification notification : notifications) { if (!notification.isSuccessful()) { log.log(Level.WARNING, "Notification to device " + notification.getDevice().getToken() + " from task " + taskName + " wasn't successful.", notification.getException()); // Check if APNS returned an error-response packet. ResponsePacket errorResponse = notification.getResponse(); if (errorResponse != null) { if (errorResponse.getStatus() == 8) { String invalidToken = notification.getDevice().getToken(); invalidTokens.add(invalidToken); } log.warning("Error response packet: " + errorResponse.getMessage()); } } if (invalidTokens.size() > 0) { PushNotificationUtility.enqueueRemovingDeviceTokens(invalidTokens); } } }
Example #4
Source File: IphonePushServiceController.java From sctalk with Apache License 2.0 | 4 votes |
@PostMapping(value = "/toUsers") public Callable<BaseModel<?>> sendToUsers(@RequestBody IosPushReq message) { return new Callable<BaseModel<?>>() { @Override public BaseModel<?> call() throws Exception { String certKeyPath = pushServerInfo.getIos().getCertKeyPath(); String keyPassword = pushServerInfo.getIos().getCertPassword(); try { List<String> tokens = new ArrayList<String>(); for (UserToken user: message.getUserTokenList()) { String token; if (user.getUserToken() != null) { token = user.getUserToken(); } else { token = userTokenService.getToken(user.getUserId()); } if (token != null && token.startsWith("ios:")) { tokens.add(token.substring(4)); } } if (!tokens.isEmpty()) { PushNotificationPayload payload = PushNotificationPayload.alert(message.getContent()); payload.addSound("default"); payload.addCustomDictionary("time", CommonUtils.currentTimeSeconds()); payload.addCustomDictionary("msg_type", message.getMsgType()); payload.addCustomDictionary("from_id", message.getFromId()); // 群组时 if (CommonUtils.isGroup(message.getMsgType())) { payload.addCustomDictionary("group_id", message.getGroupId()); } PushedNotifications apnResults; if (pushServerInfo.isTestMode()) { apnResults = Push.payload(payload, certKeyPath, keyPassword, false, 30, tokens); } else { apnResults = Push.payload(payload, certKeyPath, keyPassword, true, 30, tokens); } if (apnResults != null) { for (PushedNotification apnResult : apnResults) { // ResponsePacket responsePacket = apnResult.getResponse(); if (apnResult.isSuccessful()) { logger.debug("推送结果:成功"); // logger.debug("推送结果:", // responsePacket.getStatus(),responsePacket.getMessage()); } else { logger.debug("推送结果:失败"); } } } } return new BaseModel<Integer>(); } catch (Exception e) { logger.error("Iphone 推送失败!", e); throw new Exception("推送失败!"); } } }; }