关于ios极光推送server端注意的地方


今天试用了极光推送API

用它是因为,大多数人说它的文档是最全的,但是用过之后,发现关于IOS的文档,还是很不够,导致走了一点弯路!

特别是服务端的代码:https://github.com/jpush/jpush-api-java-client  for java

Java代码   收藏代码
  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.         // 业务异常  
  14.         LOG.warn("Service error - ErrorCode: "  
  15.                 + msgResult.getErrorCode() + ", ErrorMessage: "  
  16.                 + msgResult.getErrorMessage());  
  17.     } else {  
  18.         // 未到达 JPush   
  19.         LOG.error("Other excepitons - "  
  20.                 + msgResult.responseResult.exceptionString);  
  21.     }  
  22. }  

 这是它的推送案例,只有android的,没有IOS的!

 

附送ios的代码:

后来发现IOS完全不能试用sendCustomMessage这个方法.

 

Java代码   收藏代码
  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.                     // 业务异常  
  53.                     LOG.warn("Service error - ErrorCode: "  
  54.                             + msgResult.getErrorCode() + ", ErrorMessage: "  
  55.                             + msgResult.getErrorMessage());  
  56.                 } else {  
  57.                     // 未到达 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. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值