国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

關(guān)于ios極光推送server端注意的地方

2019-11-14 19:47:08
字體:
供稿:網(wǎng)友

今天試用了極光推送API

用它是因?yàn)椋蠖鄶?shù)人說它的文檔是最全的,但是用過之后,發(fā)現(xiàn)關(guān)于IOS的文檔,還是很不夠,導(dǎo)致走了一點(diǎn)彎路!

特別是服務(wù)端的代碼:https://github.com/jpush/jpush-api-java-client  for java

Java代碼 復(fù)制代碼 收藏代碼
  1. JPushClient jpushClient = new JPushClient(masterSecret, appKey, 0, DeviceEnum.Android, false);  
  2. CustomMessageParams params = new CustomMessageParams();  
  3. params.setReceiverType(ReceiverTypeEnum.TAG);  
  4. params.setReceiverValue(tag);  
  5.   
  6. MessageResult msgResult = jpushClient.sendCustomMessage(msgTitle, msgContent, params, null);  
  7. LOG.debug("responseContent - " + msgResult.responseResult.responseContent);  
  8. if (msgResult.isResultOK()) {  
  9.     LOG.info("msgResult - " + msgResult);  
  10.     LOG.info("messageId - " + msgResult.getMessageId());  
  11. else {  
  12.     if (msgResult.getErrorCode() > 0) {  
  13.         // 業(yè)務(wù)異常  
  14.         LOG.warn("Service error - ErrorCode: "  
  15.                 + msgResult.getErrorCode() + ", ErrorMessage: "  
  16.                 + msgResult.getErrorMessage());  
  17.     } else {  
  18.         // 未到達(dá) JPush   
  19.         LOG.error("Other excepitons - "  
  20.                 + msgResult.responseResult.exceptionString);  
  21.     }  
  22. }  
JPushClient jpushClient = new JPushClient(masterSecret, appKey, 0, DeviceEnum.Android, false);CustomMessageParams params = new CustomMessageParams();params.setReceiverType(ReceiverTypeEnum.TAG);params.setReceiverValue(tag);MessageResult msgResult = jpushClient.sendCustomMessage(msgTitle, msgContent, params, null);LOG.debug("responseContent - " + msgResult.responseResult.responseContent);if (msgResult.isResultOK()) {    LOG.info("msgResult - " + msgResult);    LOG.info("messageId - " + msgResult.getMessageId());} else {    if (msgResult.getErrorCode() > 0) {        // 業(yè)務(wù)異常        LOG.warn("Service error - ErrorCode: "                + msgResult.getErrorCode() + ", ErrorMessage: "                + msgResult.getErrorMessage());    } else {        // 未到達(dá) JPush         LOG.error("Other excepitons - "                + msgResult.responseResult.exceptionString);    }}

 這是它的推送案例,只有android的,沒有IOS的!

 

附送ios的代碼:

后來發(fā)現(xiàn)IOS完全不能試用sendCustomMessage這個(gè)方法.

 

Java代碼 復(fù)制代碼 收藏代碼
  1. /** 
  2.  *  
  3.  */  
  4. package org.haoyi.push;  
  5.   
  6. import java.util.HashMap;  
  7. import java.util.Map;  
  8.   
  9. import org.apache.log4j.Logger;  
  10.   
  11. import cn.jpush.api.JPushClient;  
  12. import cn.jpush.api.common.DeviceEnum;  
  13. import cn.jpush.api.push.IosExtras;  
  14. import cn.jpush.api.push.MessageResult;  
  15. import cn.jpush.api.push.NotificationParams;  
  16. import cn.jpush.api.push.ReceiverTypeEnum;  
  17.   
  18. /** 
  19.  * @author zfanxu 
  20.  *  
  21.  */  
  22. public class PushDemo {  
  23.     public static final int MAX = Integer.MAX_VALUE / 2;  
  24.     public static final int MIN = MAX / 2;  
  25.     PRivate static Logger LOG = Logger.getLogger(PushDemo.class);  
  26.   
  27.     public static void main(String[] args) {  
  28.   
  29.         JPushClient jpushClient = new JPushClient(Config.JPUSH_MASTER_SECRET,  
  30.                 Config.JPUSH_APPKEY, 0, DeviceEnum.IOS, false);  
  31.   
  32.         for (int i = 0; i < 1; i++) {  
  33.             String notificationContent = "show me your money!";  
  34.             NotificationParams param = new NotificationParams();  
  35.             param.setSendNo(getRandomSendNo());  
  36.             param.setReceiverType(ReceiverTypeEnum.REGISTRATION_ID);  
  37.             param.setReceiverValue("071f06f8c18");  
  38.   
  39.             Map<String, Object> extras = new HashMap<String, Object>();  
  40.             IosExtras iosExtra = new IosExtras(1, "message.wav");// badge  
  41.             // set badge and sound  
  42.             extras.put("ios", iosExtra);  
  43.   
  44.             MessageResult msgResult = jpushClient.sendNotification(  
  45.                     notificationContent, param, extras);  
  46.   
  47.             if (msgResult.isResultOK()) {  
  48.                 LOG.info("msgResult - " + msgResult);  
  49.                 LOG.info("messageId - " + msgResult.getMessageId());  
  50.             } else {  
  51.                 if (msgResult.getErrorCode() > 0) {  
  52.                     // 業(yè)務(wù)異常  
  53.                     LOG.warn("Service error - ErrorCode: "  
  54.                             + msgResult.getErrorCode() + ", ErrorMessage: "  
  55.                             + msgResult.getErrorMessage());  
  56.                 } else {  
  57.                     // 未到達(dá) JPush  
  58.                     LOG.error("Other excepitons - "  
  59.                             + msgResult.responseResult.exceptionString);  
  60.                 }  
  61.             }  
  62.   
  63.         }  
  64.     }  
  65.   
  66.     /** 
  67.      * 保持 sendNo 的唯一性是有必要的 It is very important to keep sendNo unique. 
  68.      *  
  69.      * @return sendNo 
  70.      */  
  71.     public static int getRandomSendNo() {  
  72.         return (int) (MIN + Math.random() * (MAX - MIN));  
  73.     }  
  74. }  
/** *  */package org.haoyi.push;import java.util.HashMap;import java.util.Map;import org.apache.log4j.Logger;import cn.jpush.api.JPushClient;import cn.jpush.api.common.DeviceEnum;import cn.jpush.api.push.IosExtras;import cn.jpush.api.push.MessageResult;import cn.jpush.api.push.NotificationParams;import cn.jpush.api.push.ReceiverTypeEnum;/** * @author zfanxu *  */public class PushDemo {	public static final int MAX = Integer.MAX_VALUE / 2;	public static final int MIN = MAX / 2;	private static Logger LOG = Logger.getLogger(PushDemo.class);	public static void main(String[] args) {		JPushClient jpushClient = new JPushClient(Config.JPUSH_MASTER_SECRET,				Config.JPUSH_APPKEY, 0, DeviceEnum.IOS, false);		for (int i = 0; i < 1; i++) {			String notificationContent = "show me your money!";			NotificationParams param = new NotificationParams();			param.setSendNo(getRandomSendNo());			param.setReceiverType(ReceiverTypeEnum.REGISTRATION_ID);			param.setReceiverValue("071f06f8c18");			Map<String, Object> extras = new HashMap<String, Object>();			IosExtras iosExtra = new IosExtras(1, "message.wav");// badge			// set badge and sound			extras.put("ios", iosExtra);			MessageResult msgResult = jpushClient.sendNotification(					notificationContent, param, extras);			if (msgResult.isResultOK()) {				LOG.info("msgResult - " + msgResult);				LOG.info("messageId - " + msgResult.getMessageId());			} else {				if (msgResult.getErrorCode() > 0) {					// 業(yè)務(wù)異常					LOG.warn("Service error - ErrorCode: "							+ msgResult.getErrorCode() + ", ErrorMessage: "							+ msgResult.getErrorMessage());				} else {					// 未到達(dá) JPush					LOG.error("Other excepitons - "							+ msgResult.responseResult.exceptionString);				}			}		}	}	/**	 * 保持 sendNo 的唯一性是有必要的 It is very important to keep sendNo unique.	 * 	 * @return sendNo	 */	public static int getRandomSendNo() {		return (int) (MIN + Math.random() * (MAX - MIN));	}}

 

 

先挖個(gè)坑,下班后,再填滿!

 


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 六枝特区| 深水埗区| 定兴县| 大名县| 烟台市| 永宁县| 洞头县| 宁远县| 曲靖市| 乌海市| 新竹市| 大田县| 仲巴县| 五原县| 南陵县| 临邑县| 增城市| 大英县| 延长县| 上思县| 凤凰县| 九台市| 手游| 正宁县| 赣州市| 故城县| 南康市| 石渠县| 库尔勒市| 葵青区| 蒙城县| 阿拉善盟| 宣化县| 苗栗县| 嘉义市| 昌江| 临漳县| 安化县| 房山区| 清丰县| 临猗县|