java激光推送ios_關于ios極光推送server端注意的地方

今天試用了極光推送API

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

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

Java代碼

431c9f7319ae0a0860e6dfbc055319a8.png

431c9f7319ae0a0860e6dfbc055319a8.png

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代碼

431c9f7319ae0a0860e6dfbc055319a8.png

431c9f7319ae0a0860e6dfbc055319a8.png

/**

*

*/

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

}

}

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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/532874.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/532874.shtml
英文地址,請注明出處:http://en.pswp.cn/news/532874.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

日是這一年的等幾天Java代碼_java中計算指定日期是一年的第幾天的方法

Java輸入日期計算是這年的第幾天&#xff1a;思路通過年份區分出是閏年還是平年&#xff0c;平年 2 月 28 天&#xff0c;閏年 2 月 29 天&#xff1b;1、3、5、7、8、10、12 月份 31 天其余月份均為 30 天&#xff1b;然后將每個月的天數相加即可&#xff0c;注意如果輸入的是…

[2021-CVPR] Fine-grained Angular Contrastive Learning with Coarse Labels 論文簡析

[2021-CVPR] Fine-grained Angular Contrastive Learning with Coarse Labels 論文簡析 論文地址&#xff1a;https://arxiv.org/abs/2012.03515 代碼地址&#xff1a;https://github.com/guybuk/ANCOR 首先通俗地介紹一下細粒度&#xff08;fine-grained&#xff09;&#…

orcle mysql 查詢_Oracle與Mysql的高級查詢與難點sql

一、連接查詢 1. 內連接 內連接用于返回滿足連接條件的所有記錄。默認情況下&#xff0c;在執行連接查詢時如果沒有指定任何連接操作符&#xff0c;那么這些連接查詢都屬于內連接。 Sql 代碼 1. SELECT a.dname,b.ename from depta,empb where a.deptnob.deptno and a.deptno10…

[2020-AAAI] Revisiting Image Aesthetic Assessment via Self-Supervised Feature Learning 論文簡析

[2020-AAAI] Revisiting Image Aesthetic Assessment via Self-Supervised Feature Learning 論文簡析 論文鏈接&#xff1a;https://arxiv.org/abs/1911.11419 本文探索從自監督的角度進行美學評估。基于一個基本的動機&#xff1a;一個好的美學特征表示應該能夠辨別出不同的…

java9 堆外內存_java堆外內存泄漏排查

當考慮Java中的內存泄漏時&#xff0c;我們通常會考慮Java堆泄漏&#xff0c;即在堆中分配的對象沒有被垃圾收集。這是我在處理一臺服務器內存泄漏時的想法&#xff0c;但我即將經歷的遠超出我的想象。癥狀&#xff1a;運行Vertx應用程序(沒有交換分區)的生產服務器被Linux內存…

[2020-CVPR] Dynamic Region-Aware Convolution 論文簡析

[2020-CVPR] Dynamic Region-Aware Convolution 論文簡析 論文地址&#xff1a;https://arxiv.org/abs/2003.12243 參考代碼地址&#xff08;非官方&#xff09;&#xff1a;https://github.com/shallowtoil/DRConv-PyTorch 代碼筆者自己試了一下&#xff0c;應該是可以的&…

java activity模式_Activity的啟動模式

Android系統采用任務棧的方式來管理Activity實例。棧是后進先出的數據結構。通常一個應用程序對應一個任務棧&#xff0c;默認情況下&#xff0c;每啟動一個Activity都會入棧&#xff0c;處于棧頂位置。用戶操作的永遠都是棧頂的Activity。Activity可以層疊擺放&#xff0c;每啟…

Python 中的可執行對象 eval,exec 和 compile與其在深度學習訓練中的應用實例

Python 中的可執行對象 eval&#xff0c;exec 和 compile 與其在深度學習訓練中的應用實例 eval 計算指定表達式的值。也就是說它要執行的python代碼只能是單個表達式&#xff08;注意eval不支持任何形式的賦值操作&#xff09;&#xff0c;而不能是復雜的代碼邏輯。 eval(s…

php寫簡單接口_php寫接口的日常

php寫接口的日常/*評論列表*/public function commentListW(){$base new Base();$info $base->getUserByToken();$shop_id $info[shop_id];$page $this->data[page]?:1;$pagesize $this->data[pagesize]?:C(ROLLPAGE);$search $this->data[search];$and &…

mmdetection 使用筆記 01: 安裝與簡單的推理demo

mmdetection 使用筆記 01: 安裝與簡單的推理demo mmdetection是來自商湯和港中文聯合實驗室openmmlab推出的目標檢測工具包&#xff0c;與其同系列的還有基礎視覺包mmcv&#xff0c;圖像分類mmclassification&#xff0c;還有mmaction&#xff0c;mmaction2等等。 今天第一次…

php無限評論回復_php實現無限級評論功能_后端開發

php去除數組的鍵名的方法_后端開發在php中可以使用“array_values()”函數去除數組的鍵名&#xff0c;該函數返回包含數組中所有的值的數組&#xff0c;其語法是“array_values(array)”&#xff0c;其參數“array”表示規定的數組&#xff0c;返回值是包含數組中所有的值的數組…

錯誤類型、混淆矩陣及目標檢測常用評價指標

目標檢測常用評價指標 本文主要參考陳愷大佬在B站商湯賬號的介紹mmdetection的視頻。 檢測結果的正確/錯誤類型 真陽性&#xff08;Ture Positive&#xff09;&#xff1a;算法檢測到了某類物體&#xff08;Positive&#xff09;&#xff0c;而實際圖中也確實有這個物體&…

php顯示json,PHP解決JSON中文顯示問題

PHP如何解決JSON中文顯示問題&#xff1f;本文主要介紹了PHP JSON格式的中文顯示問題解決方法&#xff0c;本文總結了3種解決中文顯示\u開頭字符問題的方法。希望對大家有所幫助。返回json數據中文顯示的問題解決方法一&#xff1a;<?php function Notice(){include ./incl…

使用yolov5訓練自己的目標檢測數據集

使用yolov5訓練自己的目標檢測數據集 yolov4出來后不久&#xff0c;又出現了yolov5&#xff0c;沒有論文。雖然作者沒有放上和yolov4的直接測試對比&#xff0c;但在COCO數據集的測試效果還是很可觀的。很多人考慮到YOLOv5的創新性不足&#xff0c;對算法是否能夠進化&#xf…

php的integer,PHP整型 integer

整數是一個沒有小數的數字。整數規則:整數必須至少有一個數字 (0-9)整數不能包含逗號或空格整數是沒有小數點的整數可以是正數或負數整型可以用三種格式來指定&#xff1a;十進制&#xff0c; 十六進制( 以 0x 為前綴)或八進制(前綴為 0)。在以下實例中我們將測試不同的數字。 …

einops和einsum:直接操作張量的利器

einops和einsum&#xff1a;直接操作張量的利器 einops和einsum是Vision Transformer的代碼實現里出現的兩個操作tensor維度和指定tensor計算的神器&#xff0c;在卷積神經網絡里不多見&#xff0c;本文將介紹簡單介紹一下這兩樣工具&#xff0c;方便大家更好地理解Vision Tra…

php的filter input,php中filter_input函數用法分析

本文實例分析了php中filter_input函數用法。分享給大家供大家參考。具體分析如下&#xff1a;在 php5.2 中,內置了filter 模塊,用于變量的驗證和過濾,過濾變量等操作&#xff0c;這里我們看下如何直接過濾用戶輸入的內容.fliter 模塊對應的 filter_input 函數使用起來非常的簡單…

COCO 數據集格式及mmdetection中的轉換方法

COCO 數據集格式及mmdetection中的轉換方法 COCO格式 CV中的目標檢測任務不同于分類&#xff0c;其標簽的形式稍為復雜&#xff0c;有幾種常用檢測數據集格式&#xff0c;本文將簡要介紹最為常見的COCO數據集的格式。 完整的官方樣例可自行查閱&#xff0c;以下是幾項關鍵的…

php獲取h1,jQuery獲取h1-h6標題元素值方法實例

本文主要介紹了jQuery實現獲取h1-h6標題元素值的方法,涉及$(":header")選擇器操作h1-h6元素及事件響應相關技巧,需要的朋友可以參考下&#xff0c;希望能幫助到大家。1、問題背景&#xff1a;查找到h1-h6&#xff0c;并遍歷它們&#xff0c;打印出內容2、實現代碼&am…

在導入NVIDIA的apex庫時報錯 ImportError cannot import name ‘UnencryptedCookieSessionFactoryConfig‘ from

在導入NVIDIA的apex庫時報錯 ImportError: cannot import name ‘UnencryptedCookieSessionFactoryConfig’ from ‘pyramid.session’ (unknown location) 報錯 在使用NVIDIA的apex庫時報錯 ImportError: cannot import name ‘UnencryptedCookieSessionFactoryConfig’ fro…