public Notification build() { Notification notification = new Notification(); if (token != null) { notification.setToken(token); } else { throw new IllegalArgumentException("token is null!"); } notification.setPriority(priority); // TODO 这里是否把没有设置过期时间的通知都设置成无限的? notification.setExpirationDate(expirationDate); /** * * * <pre> * 因为这里有两种格式,一种是: * "aps" : { * "alert" : "You got your emails.", * "badge" : 9, * "sound" : "bingbong.aiff" * }, * * 另一种是: * "aps" : { * "alert" : { * "body" : "Bob wants to play poker", * "action-loc-key" : "PLAY" * }, * "badge" : 5, * }, * </pre> */ if (alert != null) { aps.put("alert", alert); } else { aps.put("alert", alertObject); } if (alert != null && !alertObject.isEmpty()) { logger.warn( "can not set alert and alertObject both!, https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW12"); } payload.put("aps", aps); byte[] bytes = payload.toString().getBytes(utf8); if (bytes.length > MAX_PAYLOAD_SIZE) { throw new IllegalArgumentException("payload.length >" + MAX_PAYLOAD_SIZE); } notification.setPayload(bytes); return notification; }