日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2025/3/8 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java激光推送ios_关于ios极光推送server端注意的地方 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

今天試用了極光推送API

用它是因為,大多數人說它的文檔是最全的,但是用過之后,發現關于IOS的文檔,還是很不夠,導致走了一點彎路!

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

Java代碼

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);

}

}

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這個方法.

Java代碼

/**

*

*/

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?

String?notificationContent?=? “show?me?your?money!”;

NotificationParams?param?=? new?NotificationParams();

param.setSendNo(getRandomSendNo());

param.setReceiverType(ReceiverTypeEnum.REGISTRATION_ID);

param.setReceiverValue( “071f06f8c18″);

Map?extras?=? new?HashMap();

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);

}

}

}

}

/**

*

*?@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);

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 extras = new HashMap();

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));

}

}

先挖個坑,下班后,再填滿!

總結

以上是生活随笔為你收集整理的java激光推送ios_关于ios极光推送server端注意的地方的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。