From 1082fbd8c4f1fa34320c94cabb78605a16729aab Mon Sep 17 00:00:00 2001 From: zhangqinghe Date: Tue, 9 Jun 2015 17:31:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=85=B3=E4=BA=8Ejpush.recei?= =?UTF-8?q?veNotification=E7=9A=84=E6=96=87=E6=A1=A3=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A7=E6=9C=89=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 11 +++---- document/Android_detail_api.md | 2 +- document/Common_detail_api.md | 60 +++++++++++++++++++++++++++++++--- document/iOS_detail_api.md | 25 -------------- example/index.html | 18 +++++++--- 5 files changed, 75 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index bef0a6d..baf234e 100644 --- a/README.md +++ b/README.md @@ -140,9 +140,12 @@ l## JPush PhoneGap Plugin ## window.plugins.jPushPlugin.setTagsWithAlias(tags,alias) window.plugins.jPushPlugin.setTags(tags) window.plugins.jPushPlugin.setAlias(alias) -+ 获取通知内容 ++ 获取点击通知内容 event - jpush.openNotification ++ 获取通知内容 + + event - jpush.receiveNotification + 获取自定义消息推送内容 @@ -152,9 +155,6 @@ l## JPush PhoneGap Plugin ## [通用API详细说明](document/Common_detail_api.md) #### iOS API简介 -+ 获取 APNs(通知) 推送内容 - - event - jpush.receiveNotification + 获取自定义消息推送内容 @@ -190,9 +190,8 @@ l## JPush PhoneGap Plugin ## + 获取集成日志 window.plugins.jPushPlugin.setDebugMode(mode) -+ 接收推送消息Receiver ++ 接收推送消息和点击通知 - //推荐使用event jpush.Message和jpush.openNotification, //下面这两个api 是兼容旧有的代码 window.plugins.jPushPlugin.receiveMessageInAndroidCallback(data) window.plugins.jPushPlugin.openNotificationInAndroidCallback(data) diff --git a/document/Android_detail_api.md b/document/Android_detail_api.md index ebd78c1..4a774b4 100644 --- a/document/Android_detail_api.md +++ b/document/Android_detail_api.md @@ -20,7 +20,7 @@ - false 不显示集成日志 -### 接收推送消息Receiver +### 接收消息和点击通知事件 #### API - receiveMessageInAndroidCallback 用于android收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用 diff --git a/document/Common_detail_api.md b/document/Common_detail_api.md index ffe6fa9..8b8a2f2 100644 --- a/document/Common_detail_api.md +++ b/document/Common_detail_api.md @@ -219,7 +219,7 @@ android iOS |6008| tag/alias 超出总长度限制。|总长度最多 1K 字节| |6011| 10s内设置tag或alias大于3次| 短时间内操作过于频繁| -### 获取通知内容 +### 获取点击通知内容 #### event - jpush.openNotification @@ -234,6 +234,54 @@ android iOS - 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.openNotification,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意 + ++ 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.receiveNotification + +点击通知进入应用程序时会出发改事件 + +#####代码示例 + +- 在你需要接收通知的的js文件中加入: + + document.addEventListener("jpush.receiveNotification", onReceiveNotification, false); + +- onReceiveNotification需要这样写: + + var alertContent if(device.platform == "Android"){ alertContent=window.plugins.jPushPlugin.openNotification.alert; @@ -270,7 +318,6 @@ ps:点击通知后传递的json object 保存在window.plugins.jPushPlugin.rec ### 获取自定义消息推送内容 -### 获取自定义消息推送内容 ####event - jpush.receiveMessage @@ -290,9 +337,12 @@ ps:点击通知后传递的json object 保存在window.plugins.jPushPlugin.rec var onReceiveMessage = function(event){ try{ - var message = window.plugins.jPushPlugin.receiveMessage.message; - //var extras = window.plugins.jPushPlugin.extras - + var message + if(device.platform == "Android"){ + message = window.plugins.jPushPlugin.receiveMessage.message; + }else{ + message = event.content; + } $("#messageResult").html(message); } diff --git a/document/iOS_detail_api.md b/document/iOS_detail_api.md index ed33755..3e25d19 100644 --- a/document/iOS_detail_api.md +++ b/document/iOS_detail_api.md @@ -2,31 +2,6 @@ ### 获取 APNs(通知) 推送内容 -#### event - jpush.receiveNotification - -当iOS收到的通知时会触发这个事件 - - -#####代码示例 - -- 在你需要接收通知的的js文件中加入: - - document.addEventListener("jpush.receiveNotification", onReceiveNotification, false); - -- onOpenNotification需要这样写: - - var onReceiveNotification = function(event){ - try{ - var alert = event.aps.alert; - console.log("JPushPlugin:onReceiveNotification key aps.alert:"+alert); - } - catch(exeption){ - console.log(exception) - } - } - - - #### API - receiveMessageIniOSCallback diff --git a/example/index.html b/example/index.html index 36fdd33..8e421ae 100644 --- a/example/index.html +++ b/example/index.html @@ -54,8 +54,12 @@ } var onReceiveNotification = function(event){ try{ - - var alert = window.plugins.jPushPlugin.receiveNotification.alert; + var alert + if(device.platform == "Android"){ + alert = window.plugins.jPushPlugin.receiveNotification.alert; + }else{ + alert = event.aps.alert; + } $("#notificationResult").html(alert); } @@ -65,9 +69,15 @@ } var onReceiveMessage = function(event){ try{ - var message = window.plugins.jPushPlugin.receiveMessage.message; + + var message + if(device.platform == "Android"){ + message = window.plugins.jPushPlugin.receiveMessage.message; + }else{ + message = event.content; + } //var extras = window.plugins.jPushPlugin.extras - + $("#messageResult").html(message); }