Places to note about iOS Aurora push server side

Source: Internet
Author: User

Try the Aurora push API today

It's because most people say it's the most complete document, but after using it, it's not enough to find out about the iOS document, which leads to a bit of a detour!

In particular, the server-side code: Https://github.com/jpush/jpush-api-java-client for Java

Java code
  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. //Business Exception
  13. Log.warn ("Service error-errorcode:"
  14. + msgresult.geterrorcode () + ", errormessage:"
  15. + msgresult.geterrormessage ());
  16. } Else {
  17. //not reached 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 ();p arams.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) {        //Business exception        Log.warn ("Service Error-errorcode:"                + Msgresult. GetErrorCode () + ", ErrorMessage:"                + msgresult.geterrormessage ());    } else {        //did not reach Jpush         log.error ("Other excepitons-"                + msgResult.responseResult.exceptionString);}    }

This is its push case, only Android, no iOS!

The code that comes with iOS:

Later found that iOS could not try Sendcustommessage this method at all.

Java code
  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. //Business Exception
  43. Log.warn ("Service error-errorcode:"
  44. + msgresult.geterrorcode () + ", errormessage:"
  45. + msgresult.geterrormessage ());
  46. } Else {
  47. //not reached Jpush
  48. Log.error ("Other excepitons-"
  49. + msgResult.responseResult.exceptionString);
  50. }
  51. }
  52. }
  53. }
  54. /** 
  55. * Maintaining Sendno uniqueness is necessary for 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);p Ublic St atic 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 ();p Aram.setsendno (Getrandomsendno ());p Aram.setreceivertype ( receivertypeenum.registration_id);p aram.setreceivervalue ("071f06f8c18"); map<string, object> extras = new HaShmap<string, object> (); Iosextras Iosextra = new Iosextras (1, "message.wav");//badge//set badge and SOUNDEXTRAS.P UT ("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) {//Business exception Log.warn ("Service error-errorcode:" + msgresult.geterrorcode () + ", E Rrormessage: "+ msgresult.geterrormessage ());} else {//did not reach Jpushlog.error ("other excepitons-" + msgResult.responseResult.exceptionString);}}} /** * Maintaining the uniqueness of sendno is necessary for It is very important to keep Sendno unique. * * @return sendno */public static int Getrandomsendno () {return (int) (MIN + math.random () * (Max-min));}}

Dig a hole first, after work, fill again!

    • Haoyipushserver.rar

Places to note about iOS Aurora push server side

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.