javapns.notification.PushedNotifications Java Examples
The following examples show how to use
javapns.notification.PushedNotifications.
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(Map<String, PushedNotifications> pushedNotifications) { notificationSender.processedPendingNotificationResponses(); for (String taskName : pushedNotifications.keySet()) { processPushedNotifications(taskName, pushedNotifications.get(taskName)); } }
Example #2
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 #3
Source File: Sender.java From io2014-codelabs with Apache License 2.0 | 5 votes |
/** * Sends an alert notification to a list of devices. * * @param alertMessage alert to be sent as a push notification * @param deviceTokens the list of tokens for devices to which the notifications should be sent * @return a list of pushed notifications that contain details on transmission results. * @throws javapns.communication.exceptions.CommunicationException thrown if an error occurred while communicating with the target * server even after a few retries. * @throws javapns.communication.exceptions.KeystoreException thrown if an error occurs with using the certificate. */ public PushedNotifications sendAlert(String alertMessage, String[] deviceTokens) throws CommunicationException, KeystoreException { log.info("Sending alert='" + alertMessage + "' to " + deviceTokens.length + " devices started at " + dateFormat.format(new Date()) + "."); PushedNotifications notifications = sendPayload(PushNotificationPayload.alert(alertMessage), deviceTokens); log.info("Sending alert='" + alertMessage + "' to " + deviceTokens.length + " devices completed at " + dateFormat.format(new Date()) + "."); return notifications; }
Example #4
Source File: Worker.java From solutions-mobile-backend-starter-java with Apache License 2.0 | 5 votes |
private void processPushedNotifications(Map<String, PushedNotifications> pushedNotifications) { notificationSender.processedPendingNotificationResponses(); for (String taskName : pushedNotifications.keySet()) { processPushedNotifications(taskName, pushedNotifications.get(taskName)); } }
Example #5
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 #6
Source File: Sender.java From solutions-mobile-backend-starter-java with Apache License 2.0 | 5 votes |
/** * Sends an alert notification to a list of devices. * * @param alertMessage alert to be sent as a push notification * @param deviceTokens the list of tokens for devices to which the notifications should be sent * @return a list of pushed notifications that contain details on transmission results. * @throws CommunicationException thrown if an error occurred while communicating with the target * server even after a few retries. * @throws KeystoreException thrown if an error occurs with using the certificate. */ public PushedNotifications sendAlert(String alertMessage, String[] deviceTokens) throws CommunicationException, KeystoreException { log.info("Sending alert='" + alertMessage + "' to " + deviceTokens.length + " devices started at " + dateFormat.format(new Date()) + "."); PushedNotifications notifications = sendPayload(PushNotificationPayload.alert(alertMessage), deviceTokens); log.info("Sending alert='" + alertMessage + "' to " + deviceTokens.length + " devices completed at " + dateFormat.format(new Date()) + "."); return notifications; }
Example #7
Source File: PushNotificationWorker.java From solutions-ios-push-notification-sample-backend-java with Apache License 2.0 | 5 votes |
private void processPushedNotifications(Map<String, PushedNotifications> pushedNotifications) { notificationSender.processedPendingNotificationResponses(); for (String taskName : pushedNotifications.keySet()) { processPushedNotifications(taskName, pushedNotifications.get(taskName)); } }
Example #8
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 #9
Source File: PushNotificationSender.java From solutions-ios-push-notification-sample-backend-java with Apache License 2.0 | 5 votes |
/** * Sends an alert notification to a list of devices. * * @param alertMessage alert to be sent as a push notification * @param deviceTokens the list of tokens for devices to which the notifications should be sent * @return a list of pushed notifications that contain details on transmission results. * @throws CommunicationException thrown if an error occurred while communicating with the target * server even after a few retries. * @throws KeystoreException thrown if an error occurs with using the certificate. */ public PushedNotifications sendAlert(String alertMessage, String[] deviceTokens) throws CommunicationException, KeystoreException { log.info("Sending alert='" + alertMessage + "' to " + deviceTokens.length + " devices started at " + dateFormat.format(new Date()) + "."); PushedNotifications notifications = sendPayload(PushNotificationPayload.alert(alertMessage), deviceTokens); log.info("Sending alert='" + alertMessage + "' to " + deviceTokens.length + " devices completed at " + dateFormat.format(new Date()) + "."); return notifications; }
Example #10
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("推送失败!"); } } }; }