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


Java PushNotificationPayload.addCustomDictionary方法代码示例

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


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

示例1: createPayload

import javapns.notification.PushNotificationPayload; //导入方法依赖的package包/类
/**
 * Create a payload to be sent to client device.
 *
 * @param alertMessage Message that is visible to end user
 * @param hiddenMessage Message that is invisible to end user
 * @return a push notification payload to send to client device
 */
public PushNotificationPayload createPayload(String alertMessage,
    String hiddenMessage) {
  if (StringUtility.isNullOrEmpty(alertMessage) || StringUtility.isNullOrEmpty(hiddenMessage)) {
    throw new IllegalArgumentException("Input arguments cannot be a null or an empty String");
  }

  PushNotificationPayload payload = new PushNotificationPayload();

  try {
    payload.addAlert(alertMessage);
    payload.addCustomDictionary("hiddenMessage", hiddenMessage);
  } catch (JSONException e) {
    log.warning(e.getClass().toString() + " " + e.getMessage());
  }

  return payload;
}
 
开发者ID:googlesamples,项目名称:io2014-codelabs,代码行数:25,代码来源:Sender.java

示例2: sendIosInvitationNotification

import javapns.notification.PushNotificationPayload; //导入方法依赖的package包/类
/**
 * Sends an invitation notification to iOS devices.
 *
 * @param iOsDevices the list of Android devices to send the notification to.
 * @param invitee the Player who has been invited.
 * @param invitationId the invitation id.
 * @param gameId the game id.
 * @param messageText invitationText to be sent.
 * @throws CommunicationException if an error occurred while sending iOS push notifications.
 */
private void sendIosInvitationNotification(List<DeviceEntity> iOsDevices, PlayerEntity invitee,
    long invitationId, long gameId, String messageText) throws CommunicationException {
  PushNotificationPayload payload = PushNotificationPayload.complex();

  try {
    payload.addAlert(messageText);
    payload.addCustomDictionary("invitationId", String.valueOf(invitationId));
    payload.addCustomDictionary("gameId", String.valueOf(gameId));
    payload.addCustomDictionary("playerId", String.valueOf(invitee.getId()));
    payload.addCustomDictionary("nickName", invitee.getNickname());

    IosNotificationService notificationService = new IosNotificationService();
    notificationService.sendPushNotification(iOsDevices, payload, invitee.getKey());
  } catch (JSONException e) {
    logger.log(Level.WARNING, "Invalid format of a push notification payload", e);
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:solutions-griddler-sample-backend-java,代码行数:28,代码来源:InvitationService.java

示例3: sendToUsers

import javapns.notification.PushNotificationPayload; //导入方法依赖的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

示例4: pushAll4Apple

import javapns.notification.PushNotificationPayload; //导入方法依赖的package包/类
@Override
	public void pushAll4Apple(MsgEntity msgEntity) {
		//群推线程数
		String	pushThreads = ResourceUtil.getConfigByName("applePushAllThread");
		//p12文件地址
		String	appleP12Path = ResourceUtil.getConfigByName("appleP12Path");
		//p12文件密码
		String	appleP12Pwd = ResourceUtil.getConfigByName("appleP12Pwd");
		//苹果推送服务器选择,true为正式服务器,false为开发者服务器
		String	applePushServer = ResourceUtil.getConfigByName("applePushServer");
		try {
			// 建立与Apple服务器连接
			AppleNotificationServer server = new AppleNotificationServerBasicImpl(
					appleP12Path, appleP12Pwd, Boolean.parseBoolean(applePushServer));
			List<PayloadPerDevice> list = new ArrayList<PayloadPerDevice>();
			// 获取要推送的tokenlist
			List<AppleTokenEntity> tokenList = commonDao.loadAll(AppleTokenEntity.class);
			for (AppleTokenEntity tokenEntity : tokenList) {
				Gson gson = new Gson();
				String msg = gson.toJson(msgEntity);
				StringBuilder sb=new StringBuilder();
				PushNotificationPayload payload = new PushNotificationPayload();
				sb.append("{'title':").append(msgEntity.getTitle()).append(",'body':").append(msgEntity.getContent()).append("}");
				payload.addBadge(0);// 图标小红圈的数值
				payload.addCustomAlertBody(msgEntity.getContent());
				payload.addCustomDictionary("data", msg);
//				payload.addCustomDictionary("content-available", 1);
				PayloadPerDevice pay = new PayloadPerDevice(payload,
						tokenEntity.getToken());// 将要推送的消息和手机唯一标识绑定
				list.add(pay);
			}
			NotificationThreads work = new NotificationThreads(server, list,
					Integer.parseInt(pushThreads));//
			work.setListener(DEBUGGING_PROGRESS_LISTENER);// 对线程的监听,一定要加上这个监听
			work.start(); // 启动线程
			work.waitForAllThreads();// 等待所有线程启动完成

		} catch (Exception e) {
			e.printStackTrace();
		}

	}
 
开发者ID:Martin404,项目名称:jmsRestful,代码行数:43,代码来源:ActiveMQProducerServiceImpl.java


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