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

今天试用了极光推送API

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

特别是服务端的代码:https://github.com/jpush/jpush-api-java-client  for 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. MessageResult msgResult = jpushClient.sendCustomMessage(msgTitle, msgContent, params, null);
  6. LOG.debug("responseContent - " + msgResult.responseResult.responseContent);
  7. if (msgResult.isResultOK()) {
  8. LOG.info("msgResult - " + msgResult);
  9. LOG.info("messageId - " + msgResult.getMessageId());
  10. } else {
  11. if (msgResult.getErrorCode() > 0) {
  12. // 业务异常
  13. LOG.warn("Service error - ErrorCode: "
  14. + msgResult.getErrorCode() + ", ErrorMessage: "
  15. + msgResult.getErrorMessage());
  16. } else {
  17. // 未到达 JPush
  18. LOG.error("Other excepitons - "
  19. + msgResult.responseResult.exceptionString);
  20. }
  21. }
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) {
// 业务异常
LOG.warn("Service error - ErrorCode: "
+ msgResult.getErrorCode() + ", ErrorMessage: "
+ msgResult.getErrorMessage());
} else {
// 未到达 JPush
LOG.error("Other excepitons - "
+ msgResult.responseResult.exceptionString);
}
}

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

附送ios的代码:

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

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

先挖个坑,下班后,再填满!

上一篇:FFMPEG 库移植到 VC 需要的步骤


下一篇:java的nio之:java的nio系列教程之Scatter/Gather