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
- 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) {
- //Business Exception
- Log.warn ("Service error-errorcode:"
- + msgresult.geterrorcode () + ", errormessage:"
- + msgresult.geterrormessage ());
- } Else {
- //not reached Jpush
- Log.error ("Other excepitons-"
- + msgResult.responseResult.exceptionString);
- }
- }
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
- /**
- *
- */
- 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) {
- //Business Exception
- Log.warn ("Service error-errorcode:"
- + msgresult.geterrorcode () + ", errormessage:"
- + msgresult.geterrormessage ());
- } Else {
- //not reached Jpush
- Log.error ("Other excepitons-"
- + msgResult.responseResult.exceptionString);
- }
- }
- }
- }
- /**
- * Maintaining Sendno uniqueness is necessary for It is very important to keep Sendno unique.
- *
- * @return Sendno
- */
- public static int Getrandomsendno () {
- return (int) (MIN + math.random () * (max-min));
- }
- }
/** * */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!
Places to note about iOS Aurora push server side