当前位置: 首页>>代码示例>>Java>>正文


Java PushedNotification类代码示例

本文整理汇总了Java中javapns.notification.PushedNotification的典型用法代码示例。如果您正苦于以下问题:Java PushedNotification类的具体用法?Java PushedNotification怎么用?Java PushedNotification使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PushedNotification类属于javapns.notification包,在下文中一共展示了PushedNotification类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: procesarResponse

import javapns.notification.PushedNotification; //导入依赖的package包/类
private static IosResponse procesarResponse(PushedNotifications result) {
    IosResponse ios = new IosResponse();
    ios.setFailure(result.getFailedNotifications().size());
    ios.setSuccess(result.getSuccessfulNotifications().size());
    ios.setResults(new ArrayList<Result>());
    for (PushedNotification notification : result) {
        LOGGER.info("[iOs] Divice: " + notification.getDevice().getToken());
        Result r = procesarPushed(notification);
        r.setIosResponse(ios);
        ios.getResults().add(r);
    }
    return ios;
}
 
开发者ID:jokoframework,项目名称:notification-server,代码行数:14,代码来源:ApnsFacade.java

示例2: procesarPushed

import javapns.notification.PushedNotification; //导入依赖的package包/类
public static Result procesarPushed(PushedNotification notification) {
    Result r = new Result();
    String diviceToken = notification.getDevice().getToken();
    if (notification.isSuccessful()) {
        r.setMessageId("OK");
    } else {
        Exception theProblem = notification.getException();
        if (theProblem != null) {
            r.setError(theProblem.getMessage());
            LOGGER.error("[iOS] Excepcion retornada al notificar "
                    + diviceToken + " " + theProblem.getMessage());
        }
        /*
         * If the problem was an error-response packet returned by
         * Apple, get it
         */
        ResponsePacket theErrorResponse = notification.getResponse();
        if (theErrorResponse != null) {
            if (GlobalCodes.iosTokenError.contains(String.valueOf(theErrorResponse.getStatus()))) {
                r.setOriginalRegistrationId(diviceToken);
            }
            r.setMessageId(String.valueOf(theErrorResponse.getIdentifier()));
            r.setStatus(theErrorResponse.getStatus());
            r.setError(theErrorResponse.getMessage());
        }
    }
    return r;
}
 
开发者ID:jokoframework,项目名称:notification-server,代码行数:29,代码来源:ApnsFacade.java

示例3: processPushedNotifications

import javapns.notification.PushedNotification; //导入依赖的package包/类
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);
    }
  }
}
 
开发者ID:googlesamples,项目名称:io2014-codelabs,代码行数:28,代码来源:Worker.java

示例4: sendPushAlert

import javapns.notification.PushedNotification; //导入依赖的package包/类
@Override
public void sendPushAlert(PushMessage pushMessage) {

	validate(pushMessage);

	try {

		PushedNotifications pushedNotifications = Push.alert(pushMessage.getMessage(), apnsCertFile,
				apnsCertPassword, apnsProduction, pushMessage.getDeviceToken());

		for (PushedNotification notification : pushedNotifications) {
			if (notification.isSuccessful()) {
				/* Apple accepted the notification and should deliver it */
				log.debug("Push notification sent successfully to: " + notification.getDevice().getToken());
				messageLogger.info(pushMessage.getDeviceToken() + " - " + pushMessage.getMessage());
				/* TODO Query the Feedback Service regularly */
			} else {
				String invalidToken = notification.getDevice().getToken();
				log.warn("Push notification failed. Invalid token: " + invalidToken, notification.getException());

				/*
				 * If the problem was an error-response packet returned by
				 * Apple, get it
				 */
				ResponsePacket theErrorResponse = notification.getResponse();
				if (theErrorResponse != null) {
					log.warn("Apple error", theErrorResponse.getMessage());
				}
				
				throw new RuntimeException("Could not send notification with token " + pushMessage.getDeviceToken());
				
			}
		}

	} catch (Exception e) {
		throw new RuntimeException(e);
	}

}
 
开发者ID:MinHalsoplan,项目名称:netcare-healthplan,代码行数:40,代码来源:PushServiceImpl.java

示例5: validateObject

import javapns.notification.PushedNotification; //导入依赖的package包/类
@Override
public boolean validateObject(PushNotificationManager manager) {
    PushedNotification notification = null;
    try {
        notification = manager.sendNotification(new BasicDevice(RandomStringUtils.randomNumeric(64)),
                PushNotificationPayload.test());
    } catch (Exception e) {
        logger.error("validate manager:[{}] due to error:[{}]", manager, ExceptionUtils.getStackTrace(e));
    }
    return notification != null && notification.isSuccessful();
}
 
开发者ID:pippo1980,项目名称:upns,代码行数:12,代码来源:PushNotificationManagerPool.java

示例6: push

import javapns.notification.PushedNotification; //导入依赖的package包/类
private void push(final APNSPushTask event, final List<Device> devices) {
	int appId = event.getMessage().getAppId();
	final PushNotificationTemplate pushNotificationTemplate = templates.payloads.get(appId);
	if (pushNotificationTemplate == null) {
		logger.warn("can not find pushNotificationTemplate with appId:[{}], ignore event:[{}]", appId, event);
		return;
	}

	pushNotificationTemplate.push(new PushNotificationProcessor() {

		@Override
		public void process(PushNotificationManager manager) throws Exception {
			//int unread = timelineRepository.unread(event.userId, event.message.appId) + 1;
			PushNotificationPayload payload = PushNotificationPayload.combined(event.message.title, 1, "default");

			for (Device device : devices) {
				if (device.token == null || device.token.length() != 64) {
					continue;
				}

				PushedNotification notification = manager.sendNotification(new BasicDevice(device.token), payload,
						false);

				if (notification != null) {
					logger.debug(
							"push message:[{}] to apns[user/device]:[{}/{}], the acknowledge is:[{}], the push result is:{}",
							event.message.title,
							device.userId,
							device.token,
							notification,
							notification.isSuccessful());
				}
			}

		}
	});
}
 
开发者ID:pippo1980,项目名称:upns,代码行数:38,代码来源:APNSPushTaskConsumer.java

示例7: processPushedNotifications

import javapns.notification.PushedNotification; //导入依赖的package包/类
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);
    }
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:solutions-ios-push-notification-sample-backend-java,代码行数:28,代码来源:PushNotificationWorker.java

示例8: sendToUsers

import javapns.notification.PushedNotification; //导入依赖的package包/类
@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("推送失败!");
            }
        }
    };
}
 
开发者ID:ccfish86,项目名称:sctalk,代码行数:72,代码来源:IphonePushServiceController.java


注:本文中的javapns.notification.PushedNotification类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。