mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2025-04-28 21:30:11 +08:00
fix android message and notification event
This commit is contained in:
parent
ce8ca9f8f8
commit
7fcefce3ce
11
README.md
11
README.md
@ -130,6 +130,14 @@
|
||||
window.plugins.jPushPlugin.setTagsWithAlias(tags,alias)
|
||||
window.plugins.jPushPlugin.setTags(tags)
|
||||
window.plugins.jPushPlugin.setAlias(alias)
|
||||
+ 获取通知内容
|
||||
|
||||
event - jpush.openNotification
|
||||
|
||||
+ 获取自定义消息推送内容
|
||||
|
||||
event - jpush.receiveMessage
|
||||
|
||||
|
||||
[通用API详细说明](document/Common_detail_api.md)
|
||||
|
||||
@ -137,7 +145,6 @@
|
||||
+ 获取 APNs(通知) 推送内容
|
||||
|
||||
event - jpush.receiveNotification
|
||||
event - jpush.openNotification
|
||||
|
||||
+ 获取自定义消息推送内容
|
||||
|
||||
@ -175,6 +182,8 @@
|
||||
|
||||
+ 接收推送消息Receiver
|
||||
|
||||
//推荐使用event jpush.Message和jpush.openNotification,
|
||||
//下面这两个api 是兼容旧有的代码
|
||||
window.plugins.jPushPlugin.receiveMessageInAndroidCallback(data)
|
||||
window.plugins.jPushPlugin.openNotificationInAndroidCallback(data)
|
||||
|
||||
|
@ -205,6 +205,8 @@ android iOS
|
||||
####错误码定义
|
||||
|
||||
|
||||
|
||||
|
||||
|Code|描述|详细解释|
|
||||
|-|-|-|
|
||||
|6001| 无效的设置,tag/alias 不应参数都为 null||
|
||||
@ -217,3 +219,107 @@ android iOS
|
||||
|6008| tag/alias 超出总长度限制。|总长度最多 1K 字节|
|
||||
|6011| 10s内设置tag或alias大于3次| 短时间内操作过于频繁|
|
||||
|
||||
### 获取通知内容
|
||||
|
||||
#### event - jpush.openNotification
|
||||
|
||||
点击通知进入应用程序时会出发改事件
|
||||
|
||||
#####代码示例
|
||||
|
||||
- 在你需要接收通知的的js文件中加入:
|
||||
|
||||
document.addEventListener("jpush.openNotification", onOpenNotification, false);
|
||||
|
||||
- onOpenNotification需要这样写:
|
||||
|
||||
|
||||
var alertContent
|
||||
if(device.platform == "Android"){
|
||||
alertContent=window.plugins.jPushPlugin.openNotification.alert;
|
||||
}else{
|
||||
alertContent = event.aps.alert;
|
||||
}
|
||||
alert("open Notificaiton:"+alertContent);
|
||||
|
||||
ps:点击通知后传递的json object 保存在window.plugins.jPushPlugin.receiveNotification,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意
|
||||
|
||||
+ android
|
||||
|
||||
{"alert":"ding",
|
||||
"extras":{
|
||||
"cn.jpush.android.MSG_ID":"1691785879",
|
||||
"app":"com.thi.pushtest",
|
||||
"cn.jpush.android.ALERT":"ding",
|
||||
"cn.jpush.android.EXTRA":{},
|
||||
"cn.jpush.android.PUSH_ID":"1691785879",
|
||||
"cn.jpush.android.NOTIFICATION_ID":1691785879,
|
||||
"cn.jpush.android.NOTIFICATION_TYPE":"0"}}
|
||||
|
||||
+ iOS
|
||||
|
||||
{
|
||||
"aps":{
|
||||
"badge":1,
|
||||
"sound":"default",
|
||||
"alert":"今天去哪儿"
|
||||
},
|
||||
"_j_msgid":154604475
|
||||
}
|
||||
|
||||
|
||||
### 获取自定义消息推送内容
|
||||
|
||||
### 获取自定义消息推送内容
|
||||
|
||||
####event - jpush.receiveMessage
|
||||
|
||||
收到应用内消息时触发这个事件
|
||||
|
||||
`推荐使用事件的方式传递,但同时保留了receiveMessageIniOSCallback的回调函数,兼容以前的代码`
|
||||
|
||||
|
||||
#####代码示例
|
||||
|
||||
- 在你需要接收通知的的js文件中加入:
|
||||
|
||||
document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);
|
||||
|
||||
- onReceiveMessage需要这样写:
|
||||
|
||||
|
||||
var onReceiveMessage = function(event){
|
||||
try{
|
||||
var message = window.plugins.jPushPlugin.receiveMessage.message;
|
||||
//var extras = window.plugins.jPushPlugin.extras
|
||||
|
||||
$("#messageResult").html(message);
|
||||
|
||||
}
|
||||
catch(exception){
|
||||
console.log("JPushPlugin:onReceiveMessage-->"+exception);
|
||||
}
|
||||
}
|
||||
|
||||
ps:点击通知后传递的json object 保存在window.plugins.jPushPlugin.receiveNotification,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意
|
||||
|
||||
+ android
|
||||
|
||||
{"message":"今天去哪儿",
|
||||
"extras"{
|
||||
"cn.jpush.android.MSG_ID":"154378013",
|
||||
"cn.jpush.android.CONTENT_TYPE":"",
|
||||
"cn.jpush.android.EXTRA":{"key":"不添没有"}
|
||||
}
|
||||
}
|
||||
+ iOS
|
||||
|
||||
{
|
||||
"content":"今天去哪儿",
|
||||
"extras":
|
||||
{
|
||||
"key":"不填写没有"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,70 +24,7 @@
|
||||
console.log(exception)
|
||||
}
|
||||
}
|
||||
|
||||
#### event - jpush.openNotification
|
||||
|
||||
点击通知进入应用程序时会出发改事件
|
||||
|
||||
#####代码示例
|
||||
|
||||
- 在你需要接收通知的的js文件中加入:
|
||||
|
||||
document.addEventListener("jpush.openNotification", onOpenNotification, false);
|
||||
|
||||
- onOpenNotification需要这样写:
|
||||
|
||||
|
||||
var onOpenNotification = function(event){
|
||||
try{
|
||||
|
||||
var alert = event.aps.alert;
|
||||
console.log("JPushPlugin:onPpenNotification key aps.alert:"+alert);
|
||||
}
|
||||
catch(exception){
|
||||
console.log("JPushPlugin:onPpenNotification"+exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
### 获取自定义消息推送内容
|
||||
|
||||
####event - jpush.receiveMessage
|
||||
|
||||
收到应用内消息时触发这个事件
|
||||
|
||||
`推荐使用事件的方式传递,但同时保留了receiveMessageIniOSCallback的回调函数,兼容以前的代码`
|
||||
|
||||
|
||||
#####代码示例
|
||||
|
||||
- 在你需要接收通知的的js文件中加入:
|
||||
|
||||
document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);
|
||||
|
||||
- onReceiveMessage需要这样写:
|
||||
|
||||
|
||||
var onReceiveMessage = function(event){
|
||||
try{
|
||||
var eventMessage="{";
|
||||
for(var key in event){
|
||||
if(key=="type"){
|
||||
break
|
||||
}
|
||||
eventMessage+=key+":"+JSON.stringify(event[key])+"\n"
|
||||
console.log(key+":"+JSON.stringify(event[key]));
|
||||
|
||||
}
|
||||
eventMessage+="}";
|
||||
$("#messageResult").html(eventMessage);
|
||||
}
|
||||
catch(exception){
|
||||
console.log("JPushPlugin:onReceiveMessage"+exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -39,12 +39,17 @@
|
||||
}
|
||||
var onOpenNotification = function(event){
|
||||
try{
|
||||
|
||||
var alertContent = event.aps.alert;
|
||||
var alertContent
|
||||
if(device.platform == "Android"){
|
||||
alertContent=window.plugins.jPushPlugin.openNotification.alert;
|
||||
}else{
|
||||
alertContent = event.aps.alert;
|
||||
}
|
||||
alert("open Notificaiton:"+alertContent);
|
||||
|
||||
}
|
||||
catch(exception){
|
||||
console.log("JPushPlugin:onPpenNotification"+exception);
|
||||
console.log("JPushPlugin:onOpenNotification"+exception);
|
||||
}
|
||||
}
|
||||
var onReceiveNotification = function(event){
|
||||
@ -67,22 +72,14 @@
|
||||
}
|
||||
var onReceiveMessage = function(event){
|
||||
try{
|
||||
|
||||
var eventMessage="{";
|
||||
for(var key in event){
|
||||
if(key=="type"){
|
||||
break
|
||||
}
|
||||
eventMessage+=key+":"+JSON.stringify(event[key])+"\n"
|
||||
console.log(key+":"+JSON.stringify(event[key]));
|
||||
|
||||
}
|
||||
eventMessage+="}";
|
||||
$("#messageResult").html(eventMessage);
|
||||
|
||||
var message = window.plugins.jPushPlugin.receiveMessage.message;
|
||||
//var extras = window.plugins.jPushPlugin.extras
|
||||
|
||||
$("#messageResult").html(message);
|
||||
|
||||
}
|
||||
catch(exception){
|
||||
console.log("JPushPlugin:onReceiveMessage"+exception);
|
||||
console.log("JPushPlugin:onReceiveMessage-->"+exception);
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,7 +89,7 @@
|
||||
window.plugins.jPushPlugin.init();
|
||||
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
|
||||
|
||||
if(JPushPlugin.prototype.isPlatformIOS()){
|
||||
if(device.platform == "Android"){
|
||||
window.plugins.jPushPlugin.setDebugModeFromIos();
|
||||
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
|
||||
}else{
|
||||
|
@ -126,8 +126,15 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
String js = String
|
||||
.format("window.plugins.jPushPlugin.receiveMessageInAndroidCallback('%s');",
|
||||
data.toString());
|
||||
|
||||
|
||||
try {
|
||||
instance.webView.sendJavascript(js);
|
||||
|
||||
// String jsEvent=String
|
||||
// .format("cordova.fireDocumentEvent('jpush.receiveMessage',%s)",
|
||||
// data.toString());
|
||||
// instance.webView.sendJavascript(jsEvent);
|
||||
} catch (NullPointerException e) {
|
||||
|
||||
} catch (Exception e) {
|
||||
@ -142,13 +149,22 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
String js = String
|
||||
.format("window.plugins.jPushPlugin.openNotificationInAndroidCallback('%s');",
|
||||
data.toString());
|
||||
// {"alert":"ding",
|
||||
// "extras":{
|
||||
// "cn.jpush.android.MSG_ID":"1691785879",
|
||||
// "app":"com.thi.pushtest",
|
||||
// "cn.jpush.android.ALERT":"ding",
|
||||
// "cn.jpush.android.EXTRA":{},
|
||||
// "cn.jpush.android.PUSH_ID":"1691785879",
|
||||
// "cn.jpush.android.NOTIFICATION_ID":1691785879,
|
||||
// "cn.jpush.android.NOTIFICATION_TYPE":"0"}}
|
||||
try {
|
||||
instance.webView.sendJavascript(js);
|
||||
|
||||
String jsEvent=String
|
||||
.format("cordova.fireDocumentEvent('jpush.openNotification',%s)",
|
||||
data.toString());
|
||||
instance.webView.sendJavascript(jsEvent);
|
||||
// String jsEvent=String
|
||||
// .format("cordova.fireDocumentEvent('jpush.openNotification',%s)",
|
||||
// data.toString());
|
||||
// instance.webView.sendJavascript(jsEvent);
|
||||
} catch (NullPointerException e) {
|
||||
|
||||
} catch (Exception e) {
|
||||
|
@ -1,8 +1,13 @@
|
||||
|
||||
var JPushPlugin = function(){
|
||||
};
|
||||
|
||||
//private plugin function
|
||||
|
||||
JPushPlugin.prototype.receiveMessage={}
|
||||
JPushPlugin.prototype.openNotification={}
|
||||
|
||||
|
||||
JPushPlugin.prototype.isPlatformIOS = function(){
|
||||
return device.platform == "iPhone" || device.platform == "iPad" || device.platform == "iPod touch" || device.platform == "iOS"
|
||||
}
|
||||
@ -140,8 +145,10 @@ JPushPlugin.prototype.receiveMessageIniOSCallback = function(data){
|
||||
JPushPlugin.prototype.receiveMessageInAndroidCallback = function(data){
|
||||
try{
|
||||
console.log("JPushPlugin:receiveMessageInAndroidCallback");
|
||||
var bToObj = JSON.parse(data);
|
||||
this.openNotification=bToObj
|
||||
cordova.fireDocumentEvent('jpush.receiveMessage',null);
|
||||
//console.log(data);
|
||||
//ecvar bToObj=JSON.parse(data);
|
||||
//var message = bToObj.message;
|
||||
//var extras = bToObj.extras;
|
||||
|
||||
@ -158,8 +165,12 @@ JPushPlugin.prototype.receiveMessageInAndroidCallback = function(data){
|
||||
//
|
||||
JPushPlugin.prototype.openNotificationInAndroidCallback = function(data){
|
||||
try{
|
||||
console.log("JPushPlugin:openNotificationInAndroidCallback");
|
||||
console.log(data);
|
||||
console.log("JPushPlugin:openNotificationInAndroidCallback");
|
||||
var bToObj = JSON.parse(data);
|
||||
this.receiveNotification=bToObj;
|
||||
cordova.fireDocumentEvent('jpush.openNotification',null);
|
||||
|
||||
//console.log(data);
|
||||
//var bToObj = JSON.parse(data);
|
||||
//var alert = bToObj.alert;
|
||||
//var extras = bToObj.extras;
|
||||
|
Loading…
x
Reference in New Issue
Block a user