forked from github/jpush-phonegap-plugin
Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c2bf4db67a | |||
| 2783be37af | |||
| ffe2fee88d | |||
| 5a1aa16e40 | |||
| f75430fcc4 | |||
| b515caf1e4 | |||
| 46b2a5ab1a | |||
| 3bccb896e2 | |||
| dfb883e24c | |||
| 1ff72e4df4 | |||
| 01a89fd293 | |||
| a1cef0866c | |||
| 24dea0821f | |||
| 20f1eb6e27 | |||
| 1bafafffc5 | |||
| cc31bc6b84 | |||
| 76153bb524 | |||
| dc33bee0e5 | |||
| 661b216359 | |||
| e117f77a38 | |||
| b9b77840ab | |||
| 7791f088b9 | |||
| c2babc3a39 | |||
| a9f5fc45bd | |||
| 02a2d04441 | |||
| 9f921ea7b5 |
@@ -1,15 +1,17 @@
|
||||
## JPush PhoneGap Plugin ##
|
||||
## JPush PhoneGap/Cordova Plugin ##
|
||||
|
||||
jpush-phonegap-plugin 支持 iOS,Android 的推送插件。
|
||||
JPush-PhoneGap-Plugin 支持 iOS, Android 的推送插件。
|
||||
|
||||
**功能特性:**
|
||||
>+ 发送推送通知
|
||||
支持 iOS, Android 的极光推送插件。
|
||||
|
||||
### 功能特性
|
||||
+ 发送推送通知
|
||||
+ 发送推送自定义消息
|
||||
+ 设置推送标签和别名
|
||||
+ 设置角标(iOS)
|
||||
|
||||
*如需要 IM 功能插件,请关注[jmessage-phonegap-plugin](https://github.com/jpush/jmessage-phonegap-plugin)*
|
||||
|
||||
*如需要 IM 功能插件,请关注 [jmessage-phonegap-plugin](https://github.com/jpush/jmessage-phonegap-plugin)*
|
||||
|
||||
## 安装 ##
|
||||
###准备工作
|
||||
@@ -25,91 +27,103 @@ jpush-phonegap-plugin 支持 iOS,Android 的推送插件。
|
||||
cordova platform add ios
|
||||
|
||||
ps:这里请注意iOS平台,必须先执行 `cordova platform add ios`,
|
||||
然后再执行`cordova plugin add xxxxx`命令,不然有一些必须要的链接库需要手动添加
|
||||
然后再执行 `cordova plugin add xxxxx` 命令,不然有一些必须要的链接库需要手动添加
|
||||
|
||||
|
||||
###Cordova CLI/Phonegap 安装 Android & iOS
|
||||
###Cordova CLI / PhoneGap 安装 Android & iOS
|
||||
|
||||
1). 安装JPush PhoneGap Plugin。 有两种方法。
|
||||
1). 安装 JPush PhoneGap Plugin, 有两种方法:
|
||||
|
||||
方法一: 在线安装
|
||||
方法一:在线安装
|
||||
|
||||
cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git --variable API_KEY=your_jpush_appkey
|
||||
通过 cordova plugins 安装,要求 phonegap/cordova CLI 5.0+ (current stable v2.1.1)
|
||||
|
||||
cordova plugin add jpush-phonegap-plugin --variable API_KEY=your_jpush_appkey
|
||||
|
||||
直接通过 url 安装(unstable)
|
||||
|
||||
cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git --variable API_KEY=your_jpush_appkey
|
||||
|
||||
方法二:下载到本地再安装
|
||||
|
||||
使用git命令将jpush phonegap插件下载的本地,将这个目录标记为`$JPUSH_PLUGIN_DIR`
|
||||
|
||||
使用 git 命令将 JPush PhoneGap 插件下载的本地,将这个目录标记为 `$JPUSH_PLUGIN_DIR`
|
||||
|
||||
git clone https://github.com/jpush/jpush-phonegap-plugin.git
|
||||
cordova plugin add $JPUSH_PLUGIN_DIR --variable API_KEY=your_jpush_appkey
|
||||
|
||||
|
||||
|
||||
2). 安装org.apache.cordova.device
|
||||
2). 安装 org.apache.cordova.device
|
||||
|
||||
cordova plugin add org.apache.cordova.device
|
||||
|
||||
|
||||
3). 在js中调用函数,初始化jpush sdk
|
||||
3). 在 js 中调用函数,初始化 JPush SDK
|
||||
|
||||
//由于 PhoneGap 插件采用了 Lazy load 的特性,所以建议在 js 文件能执行的最开始就添加
|
||||
window.plugins.jPushPlugin.init();
|
||||
//由于phonegap插件采用了Lazy load的特性, 所以这里建议在js文件能执行的最开始就加
|
||||
|
||||
|
||||
### Android 手工安装
|
||||
### Android 手动安装
|
||||
|
||||
[Android 手工安装文档地址](document/Android_handle_install.md)
|
||||
[Android 手动安装文档地址](document/Android_handle_install.md)
|
||||
|
||||
|
||||
### IOS手工安装
|
||||
### iOS 手动安装
|
||||
|
||||
[IOS手工安装文档地址](document/iOS_handle_install.md)
|
||||
[IOS手动安装文档地址](document/iOS_handle_install.md)
|
||||
|
||||
|
||||
###示例
|
||||
|
||||
1. "$JPUSH_PLUGIN_DIR/example"文件夹内找到并拷贝以下文件
|
||||
"$JPUSH_PLUGIN_DIR/example"文件夹内找到并拷贝以下文件
|
||||
|
||||
src/example/index.html to www/index.html
|
||||
src/example/css/* to www/css
|
||||
src/example/js/* to www/js
|
||||
|
||||
###关于'phonegap build'云服务
|
||||
###关于'PhoneGap build'云服务
|
||||
|
||||
该项目基于cordova实现,目前无法使用'phonegap build'云服务进行打包,建议使用本地环境进行打包
|
||||
该项目基于 cordova 实现,目前无法使用 'PhoneGap build' 云服务进行打包,建议使用本地环境进行打包
|
||||
|
||||
### API说明
|
||||
### API 说明
|
||||
|
||||
插件的API集中在JPushPlugin.js文件中,这个文件的位置如下
|
||||
插件的 API 集中在 JPushPlugin.js 文件中,该文件的具体位置如下:
|
||||
|
||||
* android:[YOUR__ANDROID_PROJECT]/assets/www/plugins/cn.jpush.phonegap.JPushPlugin/www
|
||||
* iOS:[YOUR_iOS_PROJEcT]/www/plugins/cn.jpush.phonegap.JPushPlugin/www
|
||||
Android:
|
||||
|
||||
具体的API请参考这里
|
||||
[Project]/assets/www/plugins/cn.jpush.phonegap.JPushPlugin/www
|
||||
|
||||
#### iOS和android通用API简介
|
||||
iOS:
|
||||
|
||||
+ 停止与恢复推送服务 API
|
||||
[Project]/www/plugins/cn.jpush.phonegap.JPushPlugin/www
|
||||
|
||||
具体的 API 请参考下面:
|
||||
|
||||
#### iOS 和 Android 通用 API 简介
|
||||
|
||||
+ 停止与恢复推送服务
|
||||
|
||||
window.plugins.jPushPlugin.init()
|
||||
window.plugins.jPushPlugin.stopPush()
|
||||
window.plugins.jPushPlugin.resumePush()
|
||||
window.plugins.jPushPlugin.isPushStopped(callback)
|
||||
|
||||
|
||||
+ 获取 RegistrationID API
|
||||
+ 获取 RegistrationID
|
||||
|
||||
window.plugins.jPushPlugin.getRegistrationID(callback)
|
||||
|
||||
+ 别名与标签 API
|
||||
+ 别名与标签
|
||||
|
||||
window.plugins.jPushPlugin.setTagsWithAlias(tags,alias)
|
||||
window.plugins.jPushPlugin.setTagsWithAlias(tags, alias)
|
||||
window.plugins.jPushPlugin.setTags(tags)
|
||||
window.plugins.jPushPlugin.setAlias(alias)
|
||||
|
||||
event - jpush.setTagsWithAlias //三个方法都是触发该回调事件
|
||||
|
||||
+ 获取点击通知内容
|
||||
|
||||
event - jpush.openNotification
|
||||
|
||||
+ 获取通知内容
|
||||
|
||||
event - jpush.receiveNotification
|
||||
@@ -119,99 +133,107 @@ jpush-phonegap-plugin 支持 iOS,Android 的推送插件。
|
||||
event - jpush.receiveMessage
|
||||
|
||||
|
||||
[通用API详细说明](document/Common_detail_api.md)
|
||||
[通用 API 详细说明](document/Common_detail_api.md)
|
||||
|
||||
#### iOS API简介
|
||||
|
||||
+ 获取自定义消息推送内容
|
||||
|
||||
event - jpush.receiveMessage
|
||||
//推荐使用事件的方式传递,但同时保留了receiveMessageIniOSCallback的回调函数,兼容以前的代码
|
||||
//推荐使用事件的方式传递,但同时保留了 receiveMessageIniOSCallback 的回调函数,兼容以前的代码
|
||||
window.plugins.jPushPlugin.receiveMessageIniOSCallback(data)
|
||||
|
||||
event - jpush.receiveMessage
|
||||
|
||||
+ 页面的统计
|
||||
|
||||
window.plugins.jPushPlugin.startLogPageView (pageName)
|
||||
window.plugins.jPushPlugin.stopLogPageView (pageName)
|
||||
window.plugins.jPushPlugin.beginLogPageView (pageName,duration)
|
||||
+ 设置Badge
|
||||
window.plugins.jPushPlugin.startLogPageView(pageName)
|
||||
window.plugins.jPushPlugin.stopLogPageView(pageName)
|
||||
window.plugins.jPushPlugin.beginLogPageView(pageName, duration)
|
||||
|
||||
+ 设置 Badge
|
||||
|
||||
window.plugins.jPushPlugin.setBadge(value)
|
||||
window.plugins.jPushPlugin.resetBadge()
|
||||
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(badge)
|
||||
window.plugins.JPushPlugin.getApplicationIconBadgeNumber(callback)
|
||||
|
||||
+ 本地通知
|
||||
|
||||
+ 后续版本加入
|
||||
window.plugins.JPushPlugin.addLocalNotificationForIOS(delayTime, content,
|
||||
badge, notificationID, extras)
|
||||
window.plugins.JPushPlugin.deleteLocalNotificationWithIdentifierKeyInIOS()
|
||||
window.plugins.JPushPlugin.clearAllLocalNotifications()
|
||||
|
||||
+ 日志等级设置
|
||||
|
||||
window.plugins.jPushPlugin.setDebugModeFromIos ()
|
||||
window.plugins.jPushPlugin.setDebugModeFromIos()
|
||||
window.plugins.jPushPlugin.setLogOFF()
|
||||
window.plugins.JPushPlugin.setCrashLogON()
|
||||
|
||||
+ 地理位置上报
|
||||
|
||||
window.plugins.JPushPlugin.setLocation(latitude, longitude)
|
||||
|
||||
[iOS API 详细说明](document/iOS_detail_api.md)
|
||||
|
||||
|
||||
[iOS API详细说明](document/iOS_detail_api.md)
|
||||
|
||||
|
||||
#### android API简介
|
||||
#### Android API简介
|
||||
|
||||
+ 获取集成日志
|
||||
|
||||
window.plugins.jPushPlugin.setDebugMode(mode)
|
||||
|
||||
+ 接收推送消息和点击通知
|
||||
|
||||
//下面这两个api 是兼容旧有的代码
|
||||
//下面这两个 API 是兼容旧有的代码
|
||||
window.plugins.jPushPlugin.receiveMessageInAndroidCallback(data)
|
||||
window.plugins.jPushPlugin.openNotificationInAndroidCallback(data)
|
||||
|
||||
+ 统计分析 API
|
||||
+ 统计分析
|
||||
|
||||
window.plugins.jPushPlugin.setStatisticsOpen(boolean)
|
||||
|
||||
或在 MainActivity 中的 onPause() 和 onResume() 方法中分别调用
|
||||
JPushInterface.onResume(this) 和 JPushInterface.onPause(this) 来启用统计分析功能,
|
||||
如果使用这种方式启用统计分析功能,则window.plugins.jPushPlugin.setStatisticsOpen(boolean)
|
||||
JPushInterface.onPause(this) 和 JPushInterface.onResume(this) 来启用统计分析功能,
|
||||
如果使用这种方式启用统计分析功能,则 window.plugins.jPushPlugin.setStatisticsOpen(boolean)
|
||||
方法不再有效,建议不要同时使用。
|
||||
|
||||
+ 清除通知 API
|
||||
+ 清除通知
|
||||
|
||||
window.plugins.jPushPlugin.clearAllNotification()
|
||||
|
||||
+ 通知栏样式定制 API
|
||||
+ 通知栏样式定制
|
||||
|
||||
window.plugins.jPushPlugin.setBasicPushNotificationBuilder = function()
|
||||
window.plugins.jPushPlugin.setCustomPushNotificationBuilder = function()
|
||||
|
||||
+ 设置保留最近通知条数 API
|
||||
+ 设置保留最近通知条数
|
||||
|
||||
window.plugins.jPushPlugin.setLatestNotificationNum(num)
|
||||
|
||||
+ 本地通知API
|
||||
+ 本地通知
|
||||
|
||||
window.plugins.jPushPlugin.addLocalNotification(builderId,
|
||||
content,
|
||||
title,
|
||||
notificaitonID,
|
||||
broadcastTime,
|
||||
extras)
|
||||
window.plugins.jPushPlugin.addLocalNotification(builderId, content,
|
||||
title, notificaitonID, broadcastTime, extras)
|
||||
window.plugins.jPushPlugin.removeLocalNotification(notificationID)
|
||||
window.plugins.jPushPlugin.clearLocalNotifications()
|
||||
|
||||
[Android API详细说明](document/Android_detail_api.md)
|
||||
[Android API 详细说明](document/Android_detail_api.md)
|
||||
|
||||
###常见问题
|
||||
|
||||
####1. android
|
||||
####1. Android
|
||||
|
||||
eclipse中phonegap工程import之后出现:`Type CallbackContext cannot be resolved to a type`
|
||||
解决方案:eclipse中右键单击工程名,Build Path->Config Build Path->Projects->选中 工程名称-CordovaLib->点击 add
|
||||
eclipse 中 PhoneGap 工程 import 之后出现:`Type CallbackContext cannot be resolved to a type`
|
||||
解决方案:eclipse 中右键单击工程名,Build Path -> Config Build Path -> Projects -> 选中工程名称 -> CordovaLib -> 点击 add
|
||||
|
||||
####2. iOS 设置/修改 APP_KEY
|
||||
|
||||
在PushConfig.plist 中修改。PushConfig.plist 其他值说明:
|
||||
CHANNEL 渠道标识
|
||||
IsProduction 是否生产环境(暂未启用)
|
||||
####2. iOS 设置 / 修改 APP_KEY
|
||||
|
||||
在 PushConfig.plist 中修改。
|
||||
PushConfig.plist 其他值说明:
|
||||
CHANNEL: 渠道标识
|
||||
IsProduction: 是否生产环境(暂未启用)
|
||||
|
||||
|
||||
###更多
|
||||
[JPush官网文档](http://docs.jpush.io/)
|
||||
[JPush 官网文档](http://docs.jpush.io/)
|
||||
|
||||
@@ -1,16 +1,40 @@
|
||||
## adnroid API简介
|
||||
## Android API简介
|
||||
|
||||
|
||||
### 接收通知时获得通知的信息
|
||||
|
||||
- 内容
|
||||
window.plugins.jPushPlugin.receiveNotification.alert;
|
||||
- 标题
|
||||
window.plugins.jPushPlugin.receiveNotification.title;
|
||||
- 附加字段
|
||||
window.plugins.jPushPlugin.receiveNotification.extras.yourKey;
|
||||
|
||||
### 打开通知时获得通知的信息
|
||||
|
||||
- 内容
|
||||
window.plugins.jPushPlugin.openNotification.alert;
|
||||
- 标题
|
||||
window.plugins.jPushPlugin.openNotification.title;
|
||||
- 附加字段
|
||||
window.plugins.jPushPlugin.openNotification.extras.yourKey;
|
||||
|
||||
### 收到自定义消息时获得通知的信息
|
||||
|
||||
- 内容
|
||||
window.plugins.jPushPlugin.openNotification.message;
|
||||
- 附加字段
|
||||
window.plugins.jPushPlugin.openNotification.extras.yourKey;
|
||||
|
||||
### 获取集成日志
|
||||
|
||||
#### API - setDebugMode
|
||||
|
||||
用于开启调试模式,可以查看集成JPush过程中的log,如果集成失败,可方便定位问题所在
|
||||
用于开启调试模式,可以查看集成 JPush 过程中的 Log,如果集成失败,可方便定位问题所在。
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setDebugMode (mode)
|
||||
window.plugins.jPushPlugin.setDebugMode(mode)
|
||||
|
||||
##### 参数说明
|
||||
|
||||
@@ -23,27 +47,28 @@
|
||||
### 接收消息和点击通知事件
|
||||
#### API - receiveMessageInAndroidCallback
|
||||
|
||||
用于android收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
|
||||
用于 Android 收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用。
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.receiveMessageInAndroidCallback = function(data)
|
||||
|
||||
##### 参数说明
|
||||
- data 接收到的js字符串,包含的key:value请进入该函数体查看
|
||||
|
||||
- data 接收到的 js 字符串,包含的 key:value 请进入该函数体查看。
|
||||
|
||||
##### 代码示例
|
||||
|
||||
#### API - openNotificationInAndroidCallback
|
||||
|
||||
当点击android手机的通知栏进入应用程序时,会调用这个函数,这个函数不需要主动调用,是作为回调函数来用的
|
||||
|
||||
当点击 Android 手机的通知栏进入应用程序时,会调用这个函数,这个函数不需要主动调用,是作为回调函数来用的。
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.openNotificationInAndroidCallback = function(data)
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- data js字符串
|
||||
|
||||
##### 代码示例
|
||||
@@ -51,18 +76,20 @@
|
||||
### 统计分析 API
|
||||
|
||||
#### API - onResume / onPause
|
||||
这是一个 android local api,不是js的api,请注意
|
||||
本 API 用于“用户使用时长”,“活跃用户”,“用户打开次数”的统计,并上报到服务器,在 Portal 上展示给开发者。
|
||||
|
||||
这是一个 Android Local API,不是 js 的 API,请注意
|
||||
本 API 用于“用户使用时长”,“活跃用户”,“用户打开次数”的统计,并上报到服务器,在 Portal 上展示给开发者。
|
||||
|
||||
|
||||
####接口定义
|
||||
|
||||
public static void onResume(final Activity activity)
|
||||
public static void onPause(final Activity activity)
|
||||
|
||||
####参数说明
|
||||
|
||||
+ Activity activity 当前所在的Activity。
|
||||
+ Activity 当前所在的 Activity。
|
||||
|
||||
####调用说明
|
||||
|
||||
应在所有的 Activity 的 onResume / onPause 方法里调用。
|
||||
@@ -74,6 +101,7 @@
|
||||
super.onResume();
|
||||
JPushInterface.onResume(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
@@ -82,7 +110,7 @@
|
||||
|
||||
#### API - setStatisticsOpen(boolean)
|
||||
|
||||
用于在 js 中控制是否打开应用的统计分析功能,但如果已经添加了上面的 onResume/onPause 方法,
|
||||
用于在 js 中控制是否打开应用的统计分析功能,但如果已经添加了上面的 onResume / onPause 方法,
|
||||
就不能再通过这个方法来控制统计分析功能了。
|
||||
|
||||
#### 接口定义
|
||||
@@ -90,22 +118,22 @@
|
||||
window.plugins.jPushPlugin.setStatisticsOpen(boolean)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- boolean
|
||||
-true : 打开统计分析功能
|
||||
-false: 关闭统计分析功能
|
||||
- true : 打开统计分析功能
|
||||
- false: 关闭统计分析功能
|
||||
|
||||
#### API - reportNotificationOpened
|
||||
|
||||
用于上报用户的通知栏被打开,或者用于上报用户自定义消息被展示等客户端需要统计的事件。
|
||||
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.reportNotificationOpened(msgID)
|
||||
|
||||
##### 参数说明
|
||||
- msgID
|
||||
-收到的通知或者自定义消息的id
|
||||
- 收到的通知或者自定义消息的 id
|
||||
|
||||
|
||||
### 清除通知 API
|
||||
@@ -114,7 +142,7 @@
|
||||
|
||||
推送通知到客户端时,由 JPush SDK 展现通知到通知栏上。
|
||||
|
||||
此 API 提供清除通知的功能,包括:清除所有 JPush 展现的通知(不包括非 JPush SDK 展现的)
|
||||
此 API 提供清除通知的功能,包括:清除所有 JPush 展现的通知(不包括非 JPush SDK 展现的)。
|
||||
|
||||
|
||||
##### 接口定义
|
||||
@@ -125,17 +153,17 @@
|
||||
### 设置通知静默时间 API
|
||||
### 通知栏样式定制 API
|
||||
|
||||
#### API - setBasicPushNotificationBuilder,setCustomPushNotificationBuilder
|
||||
#### API - setBasicPushNotificationBuilder, setCustomPushNotificationBuilder
|
||||
|
||||
当用户需要定制默认的通知栏样式时,则可调用此方法。
|
||||
极光 Push SDK 提供了 2 个用于定制通知栏样式的构建类:
|
||||
|
||||
- setBasicPushNotificationBuilder
|
||||
- Basic 用于定制 Android Notification 里的 defaults / flags / icon 等基础样式(行为)
|
||||
- Basic 用于定制 Android Notification 里的 defaults / flags / icon 等基础样式(行为)。
|
||||
- setCustomPushNotificationBuilder
|
||||
- 继承 Basic 进一步让开发者定制 Notification Layout
|
||||
- 继承 Basic 进一步让开发者定制 Notification Layout。
|
||||
|
||||
如果不调用此方法定制,则极光Push SDK 默认的通知栏样式是:Android标准的通知栏提示。
|
||||
如果不调用此方法定制,则极光 Push SDK 默认的通知栏样式是:Android 标准的通知栏提示。
|
||||
|
||||
##### 接口定义
|
||||
|
||||
@@ -162,35 +190,31 @@
|
||||
- num 保存的条数
|
||||
|
||||
|
||||
### 本地通知API
|
||||
### 本地通知 API
|
||||
#### API - addLocalNotification,removeLocalNotification,clearLocalNotifications
|
||||
|
||||
|
||||
本地通知API不依赖于网络,无网条件下依旧可以触发
|
||||
本地通知 API 不依赖于网络,无网条件下依旧可以触发。
|
||||
|
||||
本地通知与网络推送的通知是相互独立的,不受保留最近通知条数上限的限制
|
||||
本地通知与网络推送的通知是相互独立的,不受保留最近通知条数上限的限制。
|
||||
|
||||
本地通知的定时时间是自发送时算起的,不受中间关机等操作的影响
|
||||
本地通知的定时时间是自发送时算起的,不受中间关机等操作的影响。
|
||||
|
||||
|
||||
三个接口的功能分别为:添加一个本地通知,删除一个本地通知,删除所有的本地通知
|
||||
三个接口的功能分别为:添加一个本地通知,删除一个本地通知,删除所有的本地通知。
|
||||
|
||||
#####接口定义
|
||||
|
||||
window.plugins.jPushPlugin.addLocalNotification = function(builderId,
|
||||
content,
|
||||
title,
|
||||
notificaitonID,
|
||||
broadcastTime,
|
||||
extras)
|
||||
content, title, notificaitonID, broadcastTime, extras)
|
||||
window.plugins.jPushPlugin.removeLocalNotification = function(notificationID)
|
||||
window.plugins.jPushPlugin.clearLocalNotifications = function()
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- builderId 设置本地通知样式
|
||||
- content 设置本地通知的content
|
||||
- title 设置本地通知的title
|
||||
- notificaitonID 设置本地通知的ID
|
||||
- broadcastTime 设置本地通知触发时间,为距离当前时间的数值,单位是毫秒
|
||||
- extras 设置额外的数据信息extras为json字符串
|
||||
- builderId 设置本地通知样式。
|
||||
- content 设置本地通知的 content。
|
||||
- title 设置本地通知的 title。
|
||||
- notificaitonID 设置本地通知的 ID。
|
||||
- broadcastTime 设置本地通知触发时间,为距离当前时间的数值,单位是毫秒。
|
||||
- extras 设置额外的数据信息 extras 为 json 字符串。
|
||||
|
||||
@@ -1,15 +1,23 @@
|
||||
#Android 手工安装
|
||||
#Android 手动安装
|
||||
|
||||
下载jpush phonegap插件,并解压缩,标记插件目录为:`$JPUSH_PLUGIN_DIR`
|
||||
下载 JPush PhoneGap 插件,并解压缩,标记插件目录为:`$JPUSH_PLUGIN_DIR`
|
||||
|
||||
1. 复制:`$JPUSH_PLUGIN_DIR`/src/android/*.java 到cn/jpush/phonega/目录下(即:cn.jpush.phonegap的包下)
|
||||
2. 复制:`$JPUSH_PLUGIN_DIR`/src/android/armeabi/libjpush.so 到lib/armeabi/
|
||||
3. 复制:`$JPUSH_PLUGIN_DIR`/src/android/jpush-sdk-release2.0.6.jar 到lib/
|
||||
4. 复制:`$JPUSH_PLUGIN_DIR`/src/android/test_notification_layout.xml到res/layout/
|
||||
5. 复制:`$JPUSH_PLUGIN_DIR`/src/android/jpush_notification_icon.png到res/drawable/
|
||||
6. 修改 AndroidManifest.xml 在 manifest 节点下添加以下权限
|
||||
1. 复制:$JPUSH_PLUGIN_DIR/src/android/*.java 到 cn/jpush/phonega/ 目录下(即:cn.jpush.phonegap 的包下)
|
||||
2. 复制:$JPUSH_PLUGIN_DIR/src/android/armeabi/libjpush.so 到 lib/armeabi/
|
||||
3. 复制:$JPUSH_PLUGIN_DIR/src/android/jpush-sdk-release2.0.6.jar 到 lib/
|
||||
4. 复制:$JPUSH_PLUGIN_DIR/src/android/test_notification_layout.xml 到 res/layout/
|
||||
5. 复制:$JPUSH_PLUGIN_DIR/src/android/jpush_notification_icon.png 到 res/drawable/
|
||||
6. 复制:$JPUSH_PLUGIN_DIR/www/JPushPlugin.js 到 assets/www/plugins/cn.jpush.phonegap.JPushPlugin.www/
|
||||
和 platform_www/plugins/cn.jpush.phonegap.JPushPlugin/www/
|
||||
并在 JPushPlugin.js 文件的代码外添加:
|
||||
|
||||
<!-- Required 一些系统要求的权限,如访问网络等-->
|
||||
cordova.define("cn.jpush.phonegap.JPushPlugin.JPushPlugin", function(require, exports, module) {
|
||||
// 代码
|
||||
});
|
||||
|
||||
7. 修改 AndroidManifest.xml 在 manifest 节点下添加以下权限
|
||||
|
||||
<!-- Required 一些系统要求的权限,如访问网络等-->
|
||||
<uses-permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"/>
|
||||
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
@@ -25,24 +33,27 @@
|
||||
android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"
|
||||
android:protectionLevel="signature"/>
|
||||
|
||||
7. 修改AndroidManifest.xml 在 manifest/application 节点下添加SDK相关组件声明
|
||||
7. 修改 AndroidManifest.xml 在 manifest/application 节点下添加SDK相关组件声明
|
||||
|
||||
<activity
|
||||
android:name="cn.jpush.android.ui.PushActivity"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar"
|
||||
android:configChanges="orientation|keyboardHidden">
|
||||
<intent-filter>
|
||||
<action android:name="cn.jpush.android.ui.PushActivity"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<category android:name="$PACKAGE_NAME"/>
|
||||
<action android:name="cn.jpush.android.ui.PushActivity"/>
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<category android:name="$PACKAGE_NAME"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<!-- Required SDK核心功能-->
|
||||
|
||||
<!-- Required SDK 核心功能-->
|
||||
<service
|
||||
android:name="cn.jpush.android.service.DownloadService"
|
||||
android:enabled="true"
|
||||
android:exported="false">
|
||||
</service>
|
||||
|
||||
<!-- Required SDK 核心功能-->
|
||||
<service
|
||||
android:name="cn.jpush.android.service.PushService"
|
||||
@@ -53,22 +64,25 @@
|
||||
<action android:name="cn.jpush.android.intent.REPORT"/>
|
||||
<action android:name="cn.jpush.android.intent.PushService"/>
|
||||
<action android:name="cn.jpush.android.intent.PUSH_TIME"/>
|
||||
|
||||
</intent-filter>
|
||||
</service>
|
||||
<!-- Required SDK核心功能-->
|
||||
|
||||
<!-- Required SDK 核心功能-->
|
||||
<receiver
|
||||
android:name="cn.jpush.android.service.PushReceiver"
|
||||
android:enabled="true">
|
||||
android:name="cn.jpush.android.service.PushReceiver"
|
||||
android:enabled="true">
|
||||
<intent-filter android:priority="1000">
|
||||
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY"/>
|
||||
|
||||
<!--Required 显示通知栏 -->
|
||||
<category android:name="$PACKAGE_NAME"/>
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.USER_PRESENT"/>
|
||||
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
|
||||
</intent-filter>
|
||||
|
||||
<!-- Optional -->
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.PACKAGE_ADDED"/>
|
||||
@@ -79,30 +93,43 @@
|
||||
|
||||
<!-- User defined. For test only 用户自定义的广播接收器 -->
|
||||
<receiver
|
||||
android:name="cn.jpush.phonegap.MyReceiver"
|
||||
android:enabled="true">
|
||||
android:name="cn.jpush.phonegap.MyReceiver"
|
||||
android:enabled="true">
|
||||
<intent-filter android:priority="1000">
|
||||
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY"/>
|
||||
|
||||
<!-- Required 显示通知栏 -->
|
||||
<category android:name="$PACKAGE_NAME"/>
|
||||
</intent-filter>
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="cn.jpush.android.intent.REGISTRATION"/>
|
||||
<!-- Required 用户注册SDK的intent -->
|
||||
<action android:name="cn.jpush.android.intent.UNREGISTRATION"/>
|
||||
<action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED"/>
|
||||
<!-- Required 用户接收SDK消息的intent -->
|
||||
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED"/>
|
||||
<!-- Required 用户接收SDK通知栏信息的intent -->
|
||||
<action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED"/>
|
||||
<!-- Required 用户打开自定义通知栏的intent -->
|
||||
<action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK"/>
|
||||
<!-- Optional 用户接受Rich Push Javascript 回调函数的intent -->
|
||||
<category android:name="$PACKAGE_NAME"/>
|
||||
<action android:name="cn.jpush.android.intent.REGISTRATION"/>
|
||||
|
||||
<!-- Required 用户注册 SDK 的intent -->
|
||||
<action android:name="cn.jpush.android.intent.UNREGISTRATION"/>
|
||||
<action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED"/>
|
||||
|
||||
<!-- Required 用户接收 SDK 消息的intent -->
|
||||
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED"/>
|
||||
|
||||
<!-- Required 用户接收 SDK 通知栏信息的intent -->
|
||||
<action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED"/>
|
||||
|
||||
<!-- Required 用户打开自定义通知栏的intent -->
|
||||
<action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK"/>
|
||||
|
||||
<!-- Optional 用户接受 Rich Push Javascript 回调函数的intent -->
|
||||
<category android:name="$PACKAGE_NAME"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<!-- Required SDK核心功能-->
|
||||
<receiver android:name="cn.jpush.android.service.AlarmReceiver"/>
|
||||
<!-- Required . Enable it you can get statistics data with channel -->
|
||||
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
|
||||
<meta-data android:name="JPUSH_APPKEY" android:value="299d0fee887820e7d90a68b2"/>
|
||||
<receiver
|
||||
android:name="cn.jpush.android.service.AlarmReceiver"/>
|
||||
|
||||
<!-- Required. Enable it you can get statistics data with channel -->
|
||||
<meta-data
|
||||
android:name="JPUSH_CHANNEL" android:value="developer-default"/>
|
||||
|
||||
<meta-data
|
||||
android:name="JPUSH_APPKEY" android:value="299d0fee887820e7d90a68b2"/>
|
||||
|
||||
+119
-120
@@ -1,20 +1,20 @@
|
||||
#通用API说明
|
||||
#通用 API 说明
|
||||
|
||||
|
||||
## 停止与恢复推送服务 API
|
||||
## 停止与恢复推送服务 API
|
||||
### API - init
|
||||
|
||||
调用此API,用来开启
|
||||
调用此 API,用来开启
|
||||
JPush SDK 提供的推送服务。
|
||||
|
||||
开发者App可以通过调用停止推送服务API来停止极光推送服务。当又需要使用极光推送服务时,则必须要调用恢复推送服务 API。
|
||||
开发者 App 可以通过调用停止推送服务 API 来停止极光推送服务。当又需要使用极光推送服务时,则必须要调用恢复推送服务 API。
|
||||
|
||||
```
|
||||
本功能是一个完全本地的状态操作。也就是说:停止推送服务的状态不会保存到服务器上。
|
||||
|
||||
如果停止推送服务后,开发者App被重新安装,或者被清除数据,
|
||||
如果停止推送服务后,开发者 App 被重新安装,或者被清除数据,
|
||||
|
||||
JPush SDK 会恢复正常的默认行为。(因为保存在本地的状态数据被清除掉了)。
|
||||
JPush SDK 会恢复正常的默认行为。(因为保存在本地的状态数据被清除掉了)。
|
||||
本功能其行为类似于网络中断的效果,即:推送服务停止期间推送的消息,
|
||||
|
||||
恢复推送服务后,如果推送的消息还在保留的时长范围内,则客户端是会收到离线消息。
|
||||
@@ -25,39 +25,39 @@ JPush SDK 会恢复正常的默认行为。(因为保存在本地的状态数
|
||||
window.plugins.jPushPlugin.init()
|
||||
|
||||
### API - stopPush
|
||||
+ 在android平台
|
||||
+ 在 Android 平台
|
||||
|
||||
+ 开发者 App 可以通过调用停止推送服务 API 来停止极光推送服务,当又需要使用极光推送服务时,则必须要调用恢复推送服务 API。
|
||||
|
||||
|
||||
+ 开发者App可以通过调用停止推送服务API来停止极光推送服务。当又需要使用极光推送服务时,则必须要调用恢复推送服务 API。
|
||||
|
||||
|
||||
+ 调用了本 API 后,JPush 推送服务完全被停止。具体表现为:
|
||||
|
||||
|
||||
+ JPush Service 不在后台运行
|
||||
+ 收不到推送消息
|
||||
+ 不能通过 JPushInterface.init 恢复,需要调用resumePush恢复
|
||||
+ 不能通过 JPushInterface.init 恢复,需要调用 resumePush 恢复
|
||||
+ 极光推送所有的其他 API 调用都无效
|
||||
|
||||
+ iOS平台
|
||||
+ iOS 平台
|
||||
|
||||
+ 不推荐调用,因为这个API只是让你的DeviceToken失效,在设置-通知 中您的应用程序没有任何变化
|
||||
+ 推荐:设置一个UI界面, 提醒用户在在设置-通知关闭推送服务
|
||||
+ 不推荐调用,因为这个 API 只是让你的 DeviceToken 失效,在 设置-通知 中您的应用程序没有任何变化
|
||||
+ 推荐:设置一个 UI 界面, 提醒用户在 设置-通知 中关闭推送服务
|
||||
|
||||
### 接口定义
|
||||
|
||||
### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.stopPush()
|
||||
|
||||
|
||||
|
||||
#### API - resumePush
|
||||
|
||||
|
||||
恢复推送服务。调用了此 API 后
|
||||
|
||||
+ 在android平台
|
||||
+ 在 Android 平台
|
||||
|
||||
+ 极光推送完全恢复正常工作,
|
||||
|
||||
+ iOS平台
|
||||
|
||||
|
||||
+ 重新去APNS注册
|
||||
|
||||
|
||||
@@ -68,12 +68,12 @@ JPush SDK 会恢复正常的默认行为。(因为保存在本地的状态数
|
||||
|
||||
#### API - isPushStopped
|
||||
|
||||
+ 在android平台
|
||||
+ 在 Android 平台
|
||||
|
||||
+ 用来检查 Push Service 是否已经被停止
|
||||
|
||||
+ iOS平台
|
||||
|
||||
|
||||
+ 平台检查推送服务是否注册
|
||||
|
||||
|
||||
@@ -84,17 +84,17 @@ JPush SDK 会恢复正常的默认行为。(因为保存在本地的状态数
|
||||
|
||||
##### 参数说明
|
||||
|
||||
+ callback 回调函数,用来通知JPush的推送服务是否开启
|
||||
+ callback 回调函数,用来通知 JPush 的推送服务是否开启
|
||||
|
||||
####代码示例
|
||||
window.plugins.jPushPlugin.resumePush(callback)
|
||||
var onCallback = function(data) {
|
||||
if(data>0){
|
||||
//开启
|
||||
}else{
|
||||
//关闭
|
||||
}
|
||||
window.plugins.jPushPlugin.resumePush(callback)
|
||||
var onCallback = function(data) {
|
||||
if(data > 0){
|
||||
// 开启
|
||||
} else {
|
||||
// 关闭
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
##获取 RegistrationID API
|
||||
@@ -103,7 +103,8 @@ JPush SDK 会恢复正常的默认行为。(因为保存在本地的状态数
|
||||
|
||||
RegistrationID 定义
|
||||
|
||||
集成了 JPush SDK 的应用程序在第一次成功注册到 JPush 服务器时,JPush 服务器会给客户端返回一个唯一的该设备的标识 - RegistrationID。JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
|
||||
集成了 JPush SDK 的应用程序在第一次成功注册到 JPush 服务器时,JPush 服务器会给客户端返回一个唯一的该设备的标识 - RegistrationID。
|
||||
JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
|
||||
|
||||
应用程序可以把此 RegistrationID 保存以自己的应用服务器上,然后就可以根据 RegistrationID 来向设备推送消息或者通知。
|
||||
|
||||
@@ -121,22 +122,22 @@ RegistrationID 定义
|
||||
|
||||
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
|
||||
var onGetRegistradionID = function(data) {
|
||||
try{
|
||||
console.log("JPushPlugin:registrationID is "+data) }
|
||||
catch(exception){
|
||||
try {
|
||||
console.log("JPushPlugin:registrationID is " + data)
|
||||
} catch(exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
|
||||
##别名与标签 API
|
||||
|
||||
### API - setTagsWithAlias,setTags,setAlias
|
||||
### API - setTagsWithAlias, setTags, setAlias
|
||||
|
||||
提供几个相关 API 用来设置别名(alias)与标签(tags)。
|
||||
|
||||
这几个 API 可以在 App 里任何地方调用。
|
||||
|
||||
别名 alias
|
||||
**别名 Alias**
|
||||
|
||||
为安装了应用程序的用户,取个别名来标识。以后给该用户 Push 消息时,就可以用此别名来指定。
|
||||
|
||||
@@ -144,11 +145,11 @@ RegistrationID 定义
|
||||
|
||||
同一个应用程序内,对不同的用户,建议取不同的别名。这样,尽可能根据别名来唯一确定用户。
|
||||
|
||||
系统不限定一个别名只能指定一个用户。如果一个别名被指定到了多个用户,当给指定这个别名发消息时,服务器端API会同时给这多个用户发送消息。
|
||||
系统不限定一个别名只能指定一个用户。如果一个别名被指定到了多个用户,当给指定这个别名发消息时,服务器端 API 会同时给这多个用户发送消息。
|
||||
|
||||
举例:在一个用户要登录的游戏中,可能设置别名为 userid。游戏运营时,发现该用户 3 天没有玩游戏了,则根据 userid 调用服务器端API发通知到客户端提醒用户。
|
||||
举例:在一个用户要登录的游戏中,可能设置别名为 userid。游戏运营时,发现该用户 3 天没有玩游戏了,则根据 userid 调用服务器端 API 发通知到客户端提醒用户。
|
||||
|
||||
标签 tag
|
||||
**标签 Tag**
|
||||
|
||||
为安装了应用程序的用户,打上标签。其目的主要是方便开发者根据标签,来批量下发 Push 消息。
|
||||
|
||||
@@ -160,44 +161,39 @@ RegistrationID 定义
|
||||
|
||||
#### 接口定义
|
||||
|
||||
JPushPlugin.prototype.setTagsWithAlias = function(tags,alias)
|
||||
JPushPlugin.prototype.setTagsWithAlias = function(tags, alias)
|
||||
JPushPlugin.prototype.setTags = function(tags)
|
||||
JPushPlugin.prototype.setAlias = function(alias)
|
||||
|
||||
####使用平台
|
||||
android iOS
|
||||
|
||||
|
||||
#### 参数说明
|
||||
* tags
|
||||
* 参数类型为数组
|
||||
* 参数类型为数组
|
||||
* nil 此次调用不设置此值
|
||||
* 空集合表示取消之前的设置
|
||||
* 空集合表示取消之前的设置
|
||||
* 每次调用至少设置一个 tag,覆盖之前的设置,不是新增
|
||||
* 有效的标签组成:字母(区分大小写)、数字、下划线、汉字
|
||||
* 限制:每个 tag 命名长度限制为 40 字节,最多支持设置 100 个 tag,但总长度不得超过1K字节。(判断长度需采用UTF-8编码)
|
||||
* 单个设备最多支持设置 100 个 tag。App 全局 tag 数量无限制。
|
||||
* alias
|
||||
* 单个设备最多支持设置 100 个 tag,App 全局 tag 数量无限制。
|
||||
* alias
|
||||
* 参数类型为字符串
|
||||
* nil 此次调用不设置此值
|
||||
* 空字符串 ("")表示取消之前的设置
|
||||
* 有效的别名组成:字母(区分大小写)、数字、下划线、汉字。
|
||||
* 限制:alias 命名长度限制为 40 字节。(判断长度需采用UTF-8编码)
|
||||
|
||||
* 限制:alias 命名长度限制为 40 字节。(判断长度需采用 UTF-8 编码)
|
||||
|
||||
#### 返回值说明
|
||||
|
||||
函数本身无返回值,但需要注册`jpush.setTagsWithAlias `事件来监听设置结果
|
||||
|
||||
函数本身无返回值,但需要注册 `jpush.setTagsWithAlias` 事件来监听设置结果
|
||||
|
||||
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
|
||||
var onTagsWithAlias = function(event){
|
||||
try{
|
||||
var onTagsWithAlias = function(event) {
|
||||
try {
|
||||
console.log("onTagsWithAlias");
|
||||
var result="result code:"+event.resultCode+" ";
|
||||
result+="tags:"+event.tags+" ";
|
||||
result+="alias:"+event.alias+" ";
|
||||
var result = "result code:"+event.resultCode + " ";
|
||||
result += "tags:" + event.tags + " ";
|
||||
result += "alias:" + event.alias + " ";
|
||||
$("#tagAliasResult").html(result);
|
||||
}
|
||||
catch(exception){
|
||||
} catch(exception) {
|
||||
console.log(exception)
|
||||
}
|
||||
}
|
||||
@@ -207,17 +203,18 @@ android iOS
|
||||
|
||||
|
||||
|
||||
|Code|描述|详细解释|
|
||||
|-|-|-|
|
||||
|6001| 无效的设置,tag/alias 不应参数都为 null||
|
||||
|6002| 设置超时| 建议重试|
|
||||
|6003| alias| 字符串不合法 有效的别名、标签组成:字母(区分大小写)、数字、下划线、汉字。|
|
||||
|6004| alias超长。最多 40个字节 中文 UTF-8 是 3 个字节|
|
||||
|6005| 某一个 tag 字符串不合法| 有效的别名、标签组成:字母(区分大小写)、数字、下划线、汉字。|
|
||||
|6006| 某一个 tag 超长。|一个 tag 最多 40个字节 中文 UTF-8 是 3 个字节|
|
||||
|6007| tags 数量超出限制。最多 100个| 这是一台设备的限制。一个应用全局的标签数量无限制。|
|
||||
|6008| tag/alias 超出总长度限制。|总长度最多 1K 字节|
|
||||
|6011| 10s内设置tag或alias大于3次| 短时间内操作过于频繁|
|
||||
|Code|描述 |详细解释 |
|
||||
|----|:----------------------------------------|:--------|
|
||||
|6001|无效的设置,tag/alias 不应参数都为 null | |
|
||||
|6002|设置超时 |建议重试|
|
||||
|6003|alias 字符串不合法 |有效的别名、标签组成:字母(区分大小写)、数字、下划线、汉字。|
|
||||
|6004|alias超长。 |最多 40个字节 中文 UTF-8 是 3 个字节|
|
||||
|6005|某一个 tag 字符串不合法 |有效的别名、标签组成:字母(区分大小写)、数字、下划线、汉字。|
|
||||
|6006|某一个 tag 超长 |一个 tag 最多 40个字节 中文 UTF-8 是 3 个字节|
|
||||
|6007|tags 数量超出限制。最多 100个 |这是一台设备的限制。一个应用全局的标签数量无限制。|
|
||||
|6008|tag/alias 超出总长度限制 |总长度最多 1K 字节|
|
||||
|6011|10s内设置tag或alias大于3次 |短时间内操作过于频繁|
|
||||
|
||||
|
||||
### 获取点击通知内容
|
||||
|
||||
@@ -227,24 +224,24 @@ android iOS
|
||||
|
||||
#####代码示例
|
||||
|
||||
- 在你需要接收通知的的js文件中加入:
|
||||
|
||||
- 在你需要接收通知的的 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.openNotification,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意
|
||||
|
||||
+ android
|
||||
|
||||
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":{
|
||||
@@ -255,8 +252,8 @@ ps:点击通知后传递的json object 保存在window.plugins.jPushPlugin.ope
|
||||
"cn.jpush.android.PUSH_ID":"1691785879",
|
||||
"cn.jpush.android.NOTIFICATION_ID":1691785879,
|
||||
"cn.jpush.android.NOTIFICATION_TYPE":"0"}}
|
||||
|
||||
+ iOS
|
||||
|
||||
+ iOS
|
||||
|
||||
{
|
||||
"aps":{
|
||||
@@ -264,6 +261,8 @@ ps:点击通知后传递的json object 保存在window.plugins.jPushPlugin.ope
|
||||
"sound":"default",
|
||||
"alert":"今天去哪儿"
|
||||
},
|
||||
"key1":"value1",
|
||||
"key2":"value2",
|
||||
"_j_msgid":154604475
|
||||
}
|
||||
|
||||
@@ -275,24 +274,24 @@ ps:点击通知后传递的json object 保存在window.plugins.jPushPlugin.ope
|
||||
|
||||
#####代码示例
|
||||
|
||||
- 在你需要接收通知的的js文件中加入:
|
||||
|
||||
- 在你需要接收通知的的 js 文件中加入:
|
||||
|
||||
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
|
||||
|
||||
- onReceiveNotification需要这样写:
|
||||
|
||||
|
||||
var alertContent
|
||||
if(device.platform == "Android"){
|
||||
alertContent=window.plugins.jPushPlugin.receiveNotification.alert;
|
||||
}else{
|
||||
alertContent = event.aps.alert;
|
||||
}
|
||||
alert("open Notificaiton:"+alertContent);
|
||||
- onReceiveNotification 需要这样写:
|
||||
|
||||
ps:点击通知后传递的json object 保存在window.plugins.jPushPlugin.receiveNotification,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意
|
||||
|
||||
+ android
|
||||
|
||||
var alertContent;
|
||||
if(device.platform == "Android"){
|
||||
alertContent = window.plugins.jPushPlugin.receiveNotification.alert;
|
||||
}else{
|
||||
alertContent = event.aps.alert;
|
||||
}
|
||||
alert("open Notificaiton:" + alertContent);
|
||||
|
||||
ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.receiveNotification,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意
|
||||
|
||||
+ Android
|
||||
|
||||
{"alert":"ding",
|
||||
"extras":{
|
||||
@@ -303,8 +302,8 @@ ps:点击通知后传递的json object 保存在window.plugins.jPushPlugin.rec
|
||||
"cn.jpush.android.PUSH_ID":"1691785879",
|
||||
"cn.jpush.android.NOTIFICATION_ID":1691785879,
|
||||
"cn.jpush.android.NOTIFICATION_TYPE":"0"}}
|
||||
|
||||
+ iOS
|
||||
|
||||
+ iOS
|
||||
|
||||
{
|
||||
"aps":{
|
||||
@@ -312,6 +311,8 @@ ps:点击通知后传递的json object 保存在window.plugins.jPushPlugin.rec
|
||||
"sound":"default",
|
||||
"alert":"今天去哪儿"
|
||||
},
|
||||
"key1":"value1",
|
||||
"key2":"value2",
|
||||
"_j_msgid":154604475
|
||||
}
|
||||
|
||||
@@ -323,37 +324,37 @@ ps:点击通知后传递的json object 保存在window.plugins.jPushPlugin.rec
|
||||
|
||||
收到应用内消息时触发这个事件
|
||||
|
||||
`推荐使用事件的方式传递,但同时保留了receiveMessageIniOSCallback的回调函数,兼容以前的代码`
|
||||
`推荐使用事件的方式传递,但同时保留了 receiveMessageIniOSCallback 的回调函数,兼容以前的代码`
|
||||
|
||||
|
||||
#####代码示例
|
||||
|
||||
- 在你需要接收通知的的js文件中加入:
|
||||
|
||||
- 在你需要接收通知的的 js 文件中加入:
|
||||
|
||||
document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);
|
||||
|
||||
- onReceiveMessage需要这样写:
|
||||
|
||||
|
||||
var onReceiveMessage = function(event){
|
||||
- onReceiveMessage 需要这样写:
|
||||
|
||||
|
||||
var onReceiveMessage = function(event) {
|
||||
try{
|
||||
var message
|
||||
if(device.platform == "Android"){
|
||||
if(device.platform == "Android") {
|
||||
message = window.plugins.jPushPlugin.receiveMessage.message;
|
||||
}else{
|
||||
message = event.content;
|
||||
} else {
|
||||
message = event.content;
|
||||
}
|
||||
$("#messageResult").html(message);
|
||||
|
||||
|
||||
}
|
||||
catch(exception){
|
||||
console.log("JPushPlugin:onReceiveMessage-->"+exception);
|
||||
catch(exception) {
|
||||
console.log("JPushPlugin:onReceiveMessage-->" + exception);
|
||||
}
|
||||
}
|
||||
|
||||
ps:点击通知后传递的json object 保存在window.plugins.jPushPlugin.receiveMessage,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意
|
||||
ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.receiveMessage,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意
|
||||
|
||||
+ android
|
||||
+ Android
|
||||
|
||||
{"message":"今天去哪儿",
|
||||
"extras"{
|
||||
@@ -371,5 +372,3 @@ ps:点击通知后传递的json object 保存在window.plugins.jPushPlugin.rec
|
||||
"key":"不填写没有"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+45
-44
@@ -5,7 +5,7 @@
|
||||
|
||||
#### API - receiveMessageIniOSCallback
|
||||
|
||||
用于iOS收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
|
||||
用于 iOS 收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
|
||||
不推荐使用回调函数
|
||||
|
||||
##### 接口定义
|
||||
@@ -14,10 +14,10 @@
|
||||
|
||||
#####参数说明
|
||||
|
||||
- data 是一个js字符串使用如下代码解析,js具体key根据应用内消息来确定
|
||||
|
||||
- data 是一个 js 字符串使用如下代码解析,js 具体 key 根据应用内消息来确定
|
||||
|
||||
var bToObj = JSON.parse(data)
|
||||
|
||||
|
||||
#####返回值
|
||||
无
|
||||
|
||||
@@ -25,16 +25,17 @@
|
||||
|
||||
|
||||
### 页面的统计
|
||||
#### API - startLogPageView,stopLogPageView,beginLogPageView
|
||||
#### API - startLogPageView, stopLogPageView, beginLogPageView
|
||||
|
||||
本 API 用于“用户指定页面使用时长”的统计,并上报到服务器,在 Portal 上展示给开发者。页面统计集成正确,才能够获取正确的页面访问路径、访问深度(PV)的数据。
|
||||
|
||||
##### 接口定义
|
||||
window.plugins.jPushPlugin.prototype.startLogPageView = function(pageName)
|
||||
window.plugins.jPushPlugin.prototype.stopLogPageView = function(pageName)
|
||||
window.plugins.jPushPlugin.prototype.beginLogPageView = function(pageName,duration)
|
||||
window.plugins.jPushPlugin.prototype.beginLogPageView = function(pageName, duration)
|
||||
#####参数说明
|
||||
pageName 需要统计页面自定义名称
|
||||
|
||||
duration 自定义的页面时间
|
||||
#####调用说明
|
||||
应在所有的需要统计得页面得 viewWillAppear 和 viewWillDisappear 加入 startLogPageView 和 stopLogPageView 来统计当前页面的停留时间。
|
||||
@@ -44,17 +45,17 @@ duration 自定义的页面时间
|
||||
无
|
||||
#####代码示例
|
||||
|
||||
window.plugins.jPushPlugin.beginLogPageView("newPage",5);
|
||||
window.plugins.jPushPlugin.beginLogPageView("newPage", 5);
|
||||
window.plugins.jPushPlugin.startLogPageView("onePage");
|
||||
window.plugins.jPushPlugin.stopLogPageView("onePage");
|
||||
|
||||
### 设置Badge
|
||||
#### API - setBadge,resetBadge
|
||||
#### API - setBadge, resetBadge
|
||||
|
||||
JPush封装badge功能,允许应用上传badge值至JPush服务器,由JPush后台帮助管理每个用户所对应的推送badge值,简化了设置推送badge的操作。
|
||||
(本接口不会直接改变应用本地的角标值. 要修改本地badege值,使用 setApplicationIconBadgeNumber)
|
||||
JPush 封装 badge 功能,允许应用上传 badge 值至 JPush 服务器,由 JPush 后台帮助管理每个用户所对应的推送 badge 值,简化了设置推送 badge 的操作。
|
||||
(本接口不会直接改变应用本地的角标值. 要修改本地 badege 值,使用 setApplicationIconBadgeNumber)
|
||||
|
||||
实际应用中,开发者可以直接对badge值做增减操作,无需自己维护用户与badge值之间的对应关系。
|
||||
实际应用中,开发者可以直接对 badge 值做增减操作,无需自己维护用户与 badge 值之间的对应关系。
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.setBadge(value)
|
||||
@@ -64,7 +65,7 @@ duration 自定义的页面时间
|
||||
##### 参数说明
|
||||
value 取值范围:[0,99999]
|
||||
##### 返回值
|
||||
无,控制台会有log打印设置结果
|
||||
无,控制台会有 log 打印设置结果
|
||||
#####代码示例
|
||||
|
||||
window.plugins.jPushPlugin.setBadge(5);
|
||||
@@ -73,16 +74,16 @@ value 取值范围:[0,99999]
|
||||
#### API - setApplicationIconBadgeNumber
|
||||
|
||||
本接口直接改变应用本地的角标值.
|
||||
设置iOS的角标,当设置badge=0时为清除角标
|
||||
设置 iOS 的角标,当设置 badge = 0 时为清除角标
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.setApplicationIconBadgeNumber(badge)
|
||||
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- badge 整形,例如0,1,2
|
||||
- 当badge为0时,角标被清除
|
||||
- 当 badge 为 0 时,角标被清除
|
||||
|
||||
#####代码示例
|
||||
|
||||
@@ -91,12 +92,12 @@ value 取值范围:[0,99999]
|
||||
|
||||
#### API - getApplicationIconBadgeNumber
|
||||
|
||||
获取iOS的角标值
|
||||
获取 iOS 的角标值
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.getApplicationIconBadgeNumber(callback)
|
||||
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- callback 回调函数
|
||||
@@ -107,19 +108,19 @@ value 取值范围:[0,99999]
|
||||
window.plugins.jPushPlugin.getApplicationIconBadgeNumber(function(data){
|
||||
console.log(data);
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
### 本地通知
|
||||
#### API - addLocalNotificationForIOS
|
||||
|
||||
API用于注册本地通知
|
||||
API 用于注册本地通知
|
||||
|
||||
最多支持64个
|
||||
|
||||
##### 接口定义
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.addLocalNotificationForIOS(delayTime,content,badge,notificationID,extras)
|
||||
window.plugins.jPushPlugin.prototype.addLocalNotificationForIOS(delayTime, content, badge, notificationID, extras)
|
||||
|
||||
##### 参数说明
|
||||
|
||||
@@ -131,13 +132,13 @@ API用于注册本地通知
|
||||
|
||||
#####代码示例
|
||||
|
||||
window.plugins.jPushPlugin.addLocalNotificationForIOS(6*60*60,"本地推送内容",1,"notiId",{"key":"value"});
|
||||
window.plugins.jPushPlugin.addLocalNotificationForIOS(6*60*60, "本地推送内容", 1, "notiId", {"key":"value"});
|
||||
|
||||
#### API - deleteLocalNotificationWithIdentifierKeyInIOS
|
||||
|
||||
API删除本地推送定义
|
||||
API 删除本地推送定义
|
||||
|
||||
##### 接口定义
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.deleteLocalNotificationWithIdentifierKeyInIOS(identifierKey)
|
||||
|
||||
@@ -148,39 +149,39 @@ API删除本地推送定义
|
||||
#####代码示例
|
||||
|
||||
window.plugins.jPushPlugin.deleteLocalNotificationWithIdentifierKeyInIOS("identifier");
|
||||
|
||||
|
||||
#### API - clearAllLocalNotifications
|
||||
|
||||
API清除所有本地推送对象
|
||||
API 清除所有本地推送对象
|
||||
|
||||
##### 接口定义
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.clearAllLocalNotifications()
|
||||
|
||||
#####代码示例
|
||||
|
||||
window.plugins.jPushPlugin.clearAllLocalNotifications();
|
||||
|
||||
window.plugins.jPushPlugin.clearAllLocalNotifications();
|
||||
|
||||
### 日志等级设置
|
||||
#### API - setDebugModeFromIos
|
||||
API 用于开启Debug模式,显示更多的日志信息
|
||||
API 用于开启 Debug 模式,显示更多的日志信息
|
||||
|
||||
建议调试时开启这个选项,不调试的时候注释这句代码,这个函数setLogOFF是相反的一对
|
||||
建议调试时开启这个选项,不调试的时候注释这句代码,这个函数 setLogOFF 是相反的一对
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.setDebugModeFromIos()
|
||||
|
||||
|
||||
#####代码示例
|
||||
|
||||
window.plugins.jPushPlugin.setDebugModeFromIos();
|
||||
|
||||
#### API - setLogOFF
|
||||
|
||||
API用来关闭日志信息(除了必要的错误信息)
|
||||
API 用来关闭日志信息(除了必要的错误信息)
|
||||
|
||||
不需要任何调试信息的时候,调用此API (发布时建议调用此API,用来屏蔽日志信息,节省性能消耗)
|
||||
不需要任何调试信息的时候,调用此 API(发布时建议调用此 API,用来屏蔽日志信息,节省性能消耗)
|
||||
|
||||
##### 接口定义
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.setLogOFF()
|
||||
|
||||
@@ -190,19 +191,19 @@ API用来关闭日志信息(除了必要的错误信息)
|
||||
|
||||
#### API - setCrashLogON
|
||||
|
||||
API用于统计用户应用崩溃日志
|
||||
API 用于统计用户应用崩溃日志
|
||||
|
||||
如果需要统计Log信息,调用该接口。当你需要自己收集错误信息时,切记不要调用该接口。
|
||||
如果需要统计 Log 信息,调用该接口。当你需要自己收集错误信息时,切记不要调用该接口。
|
||||
|
||||
|
||||
##### 接口定义
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.setCrashLogON()
|
||||
|
||||
#####代码示例
|
||||
|
||||
window.plugins.jPushPlugin.setCrashLogON();
|
||||
|
||||
|
||||
### 地理位置上报
|
||||
#### API - setLocation
|
||||
API 用于统计用户地理信息
|
||||
@@ -222,16 +223,16 @@ window.plugins.jPushPlugin.setLocation(39.26,115.25);
|
||||
|
||||
### 设备平台判断
|
||||
#### API - isPlatformIOS
|
||||
API 用于区分iOS、Android平台,以便不同设置
|
||||
API 用于区分 iOS, Android 平台,以便不同设置
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.isPlatformIOS()
|
||||
|
||||
|
||||
#####代码示例
|
||||
|
||||
if(window.plugins.jPushPlugin.isPlatformIOS()){
|
||||
//iOS
|
||||
// iOS
|
||||
}else{
|
||||
//Android
|
||||
// Android
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
### IOS手工安装
|
||||
### iOS手动安装
|
||||
|
||||
下载jpush phonegap插件,并解压缩,标记插件目录为:`$JPUSH_PLUGIN_DIR`
|
||||
下载 JPush PhoneGap 插件,并解压缩,标记插件目录为:`$JPUSH_PLUGIN_DIR`
|
||||
|
||||
|
||||
1. 用xcode打开iOS工程 将`$JPUSH_PLUGIN_DIR`/src/ios/Plugins/拖到project中
|
||||
2. 将`$JPUSH_PLUGIN_DIR`/src/ios/lib/拖到project中
|
||||
1. 用 xcode 打开 iOS 工程 将 `$JPUSH_PLUGIN_DIR`/src/ios/Plugins/ 拖到 project 中
|
||||
2. 将 `$JPUSH_PLUGIN_DIR`/src/ios/lib/ 拖到 project 中
|
||||
|
||||
4. 添加以下框架,打开xocode,点击project,选择(Target -> Build Phases -> Link Binary With Libraries)
|
||||
4. 添加以下框架,打开 xcode,点击 project,选择(Target -> Build Phases -> Link Binary With Libraries)
|
||||
|
||||
CFNetwork.framework
|
||||
CoreFoundation.framework
|
||||
@@ -17,11 +17,11 @@
|
||||
UIKit.framework
|
||||
|
||||
|
||||
5. 在你的工程中创建一个新的Property List文件
|
||||
5. 在你的工程中创建一个新的 Property List 文件
|
||||
|
||||
并将其命名为PushConfig.plist,填入Portal为你的应用提供的APP_KEY等参数
|
||||
并将其命名为 PushConfig.plist,填入 Portal 为你的应用提供的 APP_KEY 等参数
|
||||
|
||||
10. 在AppDelegate.m中包含头文件
|
||||
10. 在 AppDelegate.m 中包含头文件
|
||||
|
||||
#import "APService.h"
|
||||
#import "JPushPlugin.h"
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
|
||||
//原内容保持不变
|
||||
//Required add
|
||||
//Required add
|
||||
[JPushPlugin setLaunchOptions:launchOptions];
|
||||
return YES;
|
||||
}
|
||||
@@ -47,7 +47,7 @@
|
||||
object:userInfo];
|
||||
}
|
||||
|
||||
7. 修改phonegap config.xml文件用来包含Plugin/内的插件
|
||||
7. 修改 phonegap config.xml 文件用来包含 Plugin/ 内的插件
|
||||
|
||||
|
||||
<feature name="JPushPlugin">
|
||||
@@ -56,7 +56,7 @@
|
||||
</feature>
|
||||
|
||||
|
||||
8. 复制`$JPUSH_PLUGIN_DIR`/www/PushNotification.js到工程的www目录下面
|
||||
8. 复制 `$JPUSH_PLUGIN_DIR`/www/PushNotification.js 到工程的 www 目录下面
|
||||
9. 在需要使用插件处加入
|
||||
|
||||
<script type="text/javascript" src="JPushPlugin.js"></script>
|
||||
|
||||
+96
-121
@@ -3,49 +3,47 @@
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>Phonegap Sample App</title>
|
||||
<link href="css/jquery.mobile-1.1.1.css" rel="stylesheet" type="text/css"/>
|
||||
<title>JPush Phonegap Simple Demo</title>
|
||||
<link href="css/jquery.mobile-1.1.1.css" rel="stylesheet" type="text/css" />
|
||||
<script type="text/javascript" src="js/jquery.js"></script>
|
||||
<script type="text/javascript" src="js/jquery.mobile-1.1.1.js"></script>
|
||||
<script type="text/javascript" src="cordova.js"></script>
|
||||
<script type="text/javascript">
|
||||
var onDeviceReady = function () {
|
||||
var onDeviceReady = function() {
|
||||
console.log("JPushPlugin:Device ready!");
|
||||
initiateUI();
|
||||
};
|
||||
|
||||
function getRegistrationID() {
|
||||
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
|
||||
}
|
||||
var getRegistrationID = function() {
|
||||
window.plugins.jPushPlugin.getRegistrationID(onGetRegistrationID);
|
||||
};
|
||||
|
||||
var onGetRegistradionID = function (data) {
|
||||
var onGetRegistrationID = function(data) {
|
||||
try {
|
||||
|
||||
console.log("JPushPlugin:registrationID is " + data);
|
||||
|
||||
if (data.length == 0) {
|
||||
var t1 = window.setTimeout(getRegistrationID, 1000);
|
||||
}
|
||||
$("#registrationid").html(data);
|
||||
}
|
||||
catch (exception) {
|
||||
$("#registrationId").html(data);
|
||||
} catch (exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
};
|
||||
|
||||
var onTagsWithAlias = function (event) {
|
||||
var onTagsWithAlias = function(event) {
|
||||
try {
|
||||
console.log("onTagsWithAlias");
|
||||
var result = "result code:" + event.resultCode + " ";
|
||||
result += "tags:" + event.tags + " ";
|
||||
result += "alias:" + event.alias + " ";
|
||||
$("#tagAliasResult").html(result);
|
||||
}
|
||||
catch (exception) {
|
||||
} catch (exception) {
|
||||
console.log(exception)
|
||||
}
|
||||
};
|
||||
var onOpenNotification = function (event) {
|
||||
|
||||
var onOpenNotification = function(event) {
|
||||
try {
|
||||
var alertContent;
|
||||
if (device.platform == "Android") {
|
||||
@@ -53,14 +51,13 @@
|
||||
} else {
|
||||
alertContent = event.aps.alert;
|
||||
}
|
||||
alert("open Notificaiton:" + alertContent);
|
||||
|
||||
}
|
||||
catch (exception) {
|
||||
alert("open Notification:" + alertContent);
|
||||
} catch (exception) {
|
||||
console.log("JPushPlugin:onOpenNotification" + exception);
|
||||
}
|
||||
};
|
||||
var onReceiveNotification = function (event) {
|
||||
|
||||
var onReceiveNotification = function(event) {
|
||||
try {
|
||||
var alertContent;
|
||||
if (device.platform == "Android") {
|
||||
@@ -69,37 +66,29 @@
|
||||
alertContent = event.aps.alert;
|
||||
}
|
||||
$("#notificationResult").html(alertContent);
|
||||
|
||||
}
|
||||
catch (exeption) {
|
||||
} catch (exception) {
|
||||
console.log(exception)
|
||||
}
|
||||
};
|
||||
var onReceiveMessage = function (event) {
|
||||
try {
|
||||
|
||||
var onReceiveMessage = function(event) {
|
||||
try {
|
||||
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);
|
||||
|
||||
}
|
||||
catch (exception) {
|
||||
} catch (exception) {
|
||||
console.log("JPushPlugin:onReceiveMessage-->" + exception);
|
||||
}
|
||||
};
|
||||
|
||||
var initiateUI = function () {
|
||||
|
||||
var initiateUI = function() {
|
||||
try {
|
||||
window.plugins.jPushPlugin.init();
|
||||
getRegistrationID();
|
||||
|
||||
if (device.platform != "Android") {
|
||||
window.plugins.jPushPlugin.setDebugModeFromIos();
|
||||
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
|
||||
@@ -107,117 +96,103 @@
|
||||
window.plugins.jPushPlugin.setDebugMode(true);
|
||||
window.plugins.jPushPlugin.setStatisticsOpen(true);
|
||||
}
|
||||
}
|
||||
catch (exception) {
|
||||
} catch (exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
$("#setTagWithAliasButton").click(function (ev) {
|
||||
|
||||
// window.plugins.jPushPlugin.getApplicationIconBadgeNumber(function(data){
|
||||
// console.log(data);
|
||||
// });
|
||||
|
||||
$("#setTagWithAliasButton").click(function(ev) {
|
||||
try {
|
||||
var tag1 = $("#tagText1").attr("value");
|
||||
var tag2 = $("#tagText2").attr("value");
|
||||
var tag3 = $("#tagText3").attr("value");
|
||||
var alias = $("#aliasText").attr("value");
|
||||
var dd = [];
|
||||
var tags = [];
|
||||
|
||||
if (tag1 == "" && tag2 == "" && tag3 == "") {
|
||||
if (tag1 != "") {
|
||||
tags.push(tag1);
|
||||
}
|
||||
else {
|
||||
if (tag1 != "") {
|
||||
dd.push(tag1);
|
||||
}
|
||||
if (tag2 != "") {
|
||||
dd.push(tag2);
|
||||
}
|
||||
if (tag3 != "") {
|
||||
dd.push(tag3);
|
||||
}
|
||||
if (tag2 != "") {
|
||||
tags.push(tag2);
|
||||
}
|
||||
window.plugins.jPushPlugin.setTagsWithAlias(dd, alias);
|
||||
|
||||
}
|
||||
catch (exception) {
|
||||
if (tag3 != "") {
|
||||
tags.push(tag3);
|
||||
}
|
||||
window.plugins.jPushPlugin.setTagsWithAlias(tags, alias);
|
||||
} catch (exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
|
||||
document.addEventListener("deviceready", onDeviceReady, false);
|
||||
document.addEventListener("jpush.openNotification", onOpenNotification, false);
|
||||
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
|
||||
document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);
|
||||
|
||||
|
||||
//jpush.receiveMessage
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div data-role="page" id="page">
|
||||
|
||||
<div data-role="content">
|
||||
<form>
|
||||
<div class="ui-body ui-body-b">
|
||||
|
||||
<div data-role="fieldcontain">
|
||||
<center><h3>JPushPlugin Example</h3></center>
|
||||
<span name="alias" id="alias"></span>
|
||||
<hr/>
|
||||
<label>RegistrationID: </label>
|
||||
<label id="registrationid">null</label>
|
||||
<div data-role="page" id="page">
|
||||
<div data-role="content">
|
||||
<form>
|
||||
<div class="ui-body ui-body-b">
|
||||
<div data-role="fieldcontain">
|
||||
<center>
|
||||
<h3>JPushPlugin Example</h3>
|
||||
</center>
|
||||
<span name="alias" id="alias"></span>
|
||||
<hr/>
|
||||
<label>RegistrationID: </label>
|
||||
<label id="registrationId">null</label>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label>Tags: </label>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="tagText1" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="tagText2" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="tagText3" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<label>Alias: </label>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="aliasText" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<input type="button" id="setTagWithAliasButton"
|
||||
value="Add tag and alias" />
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label id="tagAliasPrompt">设置tag/alias结果:</label>
|
||||
<label id="tagAliasResult">null</label>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label id="notificationPrompt">接受的通知内容:</label>
|
||||
<label id="notificationResult">null</label>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label id="messagePrompt">接受的自定义消息:</label>
|
||||
<label id="messageResult">null</label>
|
||||
</div>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label>Tags: </label>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="tagText1"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="tagText2"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="tagText3">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<label>Alias: </label>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="aliasText">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<input type="button" id="setTagWithAliasButton" value="Add tag and alias"/>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label id="tagAliasPrompt">设置tag/alias结果: </label>
|
||||
<label id="tagAliasResult">null</label>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label id="notificationPrompt">接受的通知内容:</label>
|
||||
<label id="notificationResult">null</label>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label id="messagePrompt">接受的自定义消息:</label>
|
||||
<label id="messageResult">null</label>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</form>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "jpush-phonegap-plugin",
|
||||
"version": "2.1.1",
|
||||
"description": "JPush for cordova plugin",
|
||||
"cordova": {
|
||||
"id": "cn.jpush.phonegap.JPushPlugin",
|
||||
"platforms": [
|
||||
"ios",
|
||||
"android"
|
||||
]
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/jpush/jpush-phonegap-plugin.git"
|
||||
},
|
||||
"keywords": [
|
||||
"JPush",
|
||||
"push",
|
||||
"ecosystem:cordova",
|
||||
"cordova-ios",
|
||||
"cordova-android"
|
||||
],
|
||||
"engines": [
|
||||
{
|
||||
"name": "cordova",
|
||||
"version": ">=3.0"
|
||||
}
|
||||
],
|
||||
"author": "jpush",
|
||||
"license": "Apache 2.0 License",
|
||||
"bugs": {
|
||||
"url": "https://github.com/jpush/jpush-phonegap-plugin/issues"
|
||||
},
|
||||
"homepage": "https://github.com/jpush/jpush-phonegap-plugin#readme"
|
||||
}
|
||||
+6
-6
@@ -163,12 +163,12 @@
|
||||
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
|
||||
<meta-data android:name="JPUSH_APPKEY" android:value="$API_KEY"/>
|
||||
</config-file>
|
||||
<source-file src="src/android/jpush-android-2.1.0.jar" target-dir="libs"/>
|
||||
<source-file src="src/android/armeabi/libjpush210.so" target-dir="libs/armeabi"/>
|
||||
<source-file src="src/android/armeabi-v7a/libjpush210.so" target-dir="libs/armeabi-v7a"/>
|
||||
<source-file src="src/android/arm64-v8a/libjpush210.so" target-dir="libs/arm64-v8a"/>
|
||||
<source-file src="src/android/x86/libjpush210.so" target-dir="libs/x86"/>
|
||||
<source-file src="src/android/x86_64/libjpush210.so" target-dir="libs/x86_64"/>
|
||||
<source-file src="src/android/jpush-android-2.1.3.jar" target-dir="libs"/>
|
||||
<source-file src="src/android/armeabi/libjpush213.so" target-dir="libs/armeabi"/>
|
||||
<source-file src="src/android/armeabi-v7a/libjpush213.so" target-dir="libs/armeabi-v7a"/>
|
||||
<source-file src="src/android/arm64-v8a/libjpush213.so" target-dir="libs/arm64-v8a"/>
|
||||
<source-file src="src/android/x86/libjpush213.so" target-dir="libs/x86"/>
|
||||
<source-file src="src/android/x86_64/libjpush213.so" target-dir="libs/x86_64"/>
|
||||
|
||||
<!--<source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jpush/phonegap"/>-->
|
||||
<source-file src="src/android/MyReceiver.java" target-dir="src/cn/jpush/phonegap"/>
|
||||
|
||||
+126
-89
@@ -37,30 +37,32 @@ import cn.jpush.android.data.JPushLocalNotification;
|
||||
public class JPushPlugin extends CordovaPlugin {
|
||||
private final static List<String> methodList =
|
||||
Arrays.asList(
|
||||
"getRegistrationID",
|
||||
"setTags",
|
||||
"setTagsWithAlias",
|
||||
"setAlias",
|
||||
"getNotification",
|
||||
"setBasicPushNotificationBuilder",
|
||||
"setCustomPushNotificationBuilder",
|
||||
"setPushTime",
|
||||
"init",
|
||||
"setDebugMode",
|
||||
"stopPush",
|
||||
"resumePush",
|
||||
"isPushStopped",
|
||||
"setLatestNotificationNum",
|
||||
"setPushTime",
|
||||
"clearAllNotification",
|
||||
"clearNotificationById",
|
||||
"addLocalNotification",
|
||||
"removeLocalNotification",
|
||||
"clearLocalNotifications",
|
||||
"onResume",
|
||||
"onPause",
|
||||
"reportNotificationOpened",
|
||||
"setStatisticsOpen");
|
||||
"addLocalNotification",
|
||||
"clearAllNotification",
|
||||
"clearLocalNotifications",
|
||||
"clearNotificationById",
|
||||
"getNotification",
|
||||
"getRegistrationID",
|
||||
"init",
|
||||
"isPushStopped",
|
||||
"onPause",
|
||||
"onResume",
|
||||
"requestPermission",
|
||||
"removeLocalNotification",
|
||||
"reportNotificationOpened",
|
||||
"resumePush",
|
||||
"setAlias",
|
||||
"setBasicPushNotificationBuilder",
|
||||
"setCustomPushNotificationBuilder",
|
||||
"setDebugMode",
|
||||
"setLatestNotificationNum",
|
||||
"setPushTime",
|
||||
"setTags",
|
||||
"setTagsWithAlias",
|
||||
"setSilenceTime",
|
||||
"setStatisticsOpen",
|
||||
"stopPush"
|
||||
);
|
||||
|
||||
private ExecutorService threadPool = Executors.newFixedThreadPool(1);
|
||||
private static JPushPlugin instance;
|
||||
@@ -68,10 +70,13 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
private static String TAG = "JPushPlugin";
|
||||
|
||||
private static boolean shouldCacheMsg = false;
|
||||
private static boolean isStatisticsOpened = true; // 是否开启统计分析功能
|
||||
private static boolean isStatisticsOpened = false; // 是否开启统计分析功能
|
||||
|
||||
public static String notificationTitle;
|
||||
public static String notificationAlert;
|
||||
public static Map<String, Object> notificationExtras = new HashMap<String, Object>();
|
||||
|
||||
public static String openNotificationTitle;
|
||||
public static String openNotificationAlert;
|
||||
public static Map<String, Object> openNotificationExtras = new HashMap<String, Object>();
|
||||
|
||||
@@ -83,54 +88,51 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
||||
super.initialize(cordova, webView);
|
||||
|
||||
Log.i(TAG, "---------------- initialize" + "-"
|
||||
+ JPushPlugin.openNotificationAlert + "-"
|
||||
+ JPushPlugin.notificationAlert);
|
||||
Log.i(TAG, "---------------- initialize" + "-" + openNotificationAlert
|
||||
+ "-" + notificationAlert);
|
||||
|
||||
cordovaActivity = this.cordova.getActivity();
|
||||
|
||||
//如果同时缓存了打开事件openNotificationAlert 和 消息事件notificationAlert,只向UI 发 打开事件。
|
||||
//这样做是为了和iOS 统一
|
||||
if (JPushPlugin.openNotificationAlert != null) {
|
||||
JPushPlugin.notificationAlert = null;
|
||||
JPushPlugin.transmitOpen(JPushPlugin.openNotificationAlert,
|
||||
JPushPlugin.openNotificationExtras);
|
||||
//如果同时缓存了打开事件 openNotificationAlert 和 消息事件 notificationAlert,只向 UI 发打开事件。
|
||||
//这样做是为了和 iOS 统一。
|
||||
if (openNotificationAlert != null) {
|
||||
notificationAlert = null;
|
||||
transmitNotificationOpen(openNotificationTitle, openNotificationAlert,
|
||||
openNotificationExtras);
|
||||
}
|
||||
if (JPushPlugin.notificationAlert != null) {
|
||||
JPushPlugin.transmitReceive(JPushPlugin.notificationAlert,
|
||||
JPushPlugin.notificationExtras);
|
||||
if (notificationAlert != null) {
|
||||
transmitNotificationReceive(notificationTitle, notificationAlert,
|
||||
notificationExtras);
|
||||
}
|
||||
//JPushInterface.init(cordova.getActivity().getApplicationContext());
|
||||
}
|
||||
|
||||
public void onPause(boolean multitasking) {
|
||||
Log.i(TAG, "---------------- onPause");
|
||||
shouldCacheMsg = true;
|
||||
if (isStatisticsOpened) {
|
||||
if (isStatisticsOpened && multitasking) {
|
||||
JPushInterface.onPause(cordovaActivity);
|
||||
}
|
||||
}
|
||||
|
||||
public void onResume(boolean multitasking) {
|
||||
shouldCacheMsg = false;
|
||||
Log.i(TAG, "---------------- onResume" + "-"
|
||||
+ JPushPlugin.openNotificationAlert + "-"
|
||||
+ JPushPlugin.notificationAlert);
|
||||
if (isStatisticsOpened) {
|
||||
Log.i(TAG, "---------------- onResume" + "-" + openNotificationAlert
|
||||
+ "-" + notificationAlert);
|
||||
if (isStatisticsOpened && multitasking) {
|
||||
JPushInterface.onResume(cordovaActivity);
|
||||
}
|
||||
if (JPushPlugin.openNotificationAlert != null) {
|
||||
JPushPlugin.notificationAlert = null;
|
||||
JPushPlugin.transmitOpen(JPushPlugin.openNotificationAlert,
|
||||
JPushPlugin.openNotificationExtras);
|
||||
if (openNotificationAlert != null) {
|
||||
notificationAlert = null;
|
||||
transmitNotificationOpen(openNotificationTitle, openNotificationAlert,
|
||||
openNotificationExtras);
|
||||
}
|
||||
if (JPushPlugin.notificationAlert != null) {
|
||||
JPushPlugin.transmitReceive(JPushPlugin.notificationAlert,
|
||||
JPushPlugin.notificationExtras);
|
||||
if (notificationAlert != null) {
|
||||
transmitNotificationReceive(notificationTitle, notificationAlert,
|
||||
notificationExtras);
|
||||
}
|
||||
}
|
||||
|
||||
private static JSONObject notificationObject(String message,
|
||||
private static JSONObject getMessageObject(String message,
|
||||
Map<String, Object> extras) {
|
||||
JSONObject data = new JSONObject();
|
||||
try {
|
||||
@@ -139,6 +141,12 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
for (Entry<String, Object> entry : extras.entrySet()) {
|
||||
if (entry.getKey().equals("cn.jpush.android.EXTRA")) {
|
||||
JSONObject jo = new JSONObject((String) entry.getValue());
|
||||
String key;
|
||||
Iterator keys = jo.keys();
|
||||
while(keys.hasNext()) {
|
||||
key = keys.next().toString();
|
||||
jExtras.put(key, jo.getString(key));
|
||||
}
|
||||
jExtras.put("cn.jpush.android.EXTRA", jo);
|
||||
} else {
|
||||
jExtras.put(entry.getKey(), entry.getValue());
|
||||
@@ -153,15 +161,22 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
return data;
|
||||
}
|
||||
|
||||
private static JSONObject openNotificationObject(String alert,
|
||||
Map<String, Object> extras) {
|
||||
private static JSONObject getNotificationObject(String title,
|
||||
String alert, Map<String, Object> extras) {
|
||||
JSONObject data = new JSONObject();
|
||||
try {
|
||||
data.put("title", title);
|
||||
data.put("alert", alert);
|
||||
JSONObject jExtras = new JSONObject();
|
||||
for (Entry<String, Object> entry : extras.entrySet()) {
|
||||
if (entry.getKey().equals("cn.jpush.android.EXTRA")) {
|
||||
JSONObject jo = new JSONObject((String) entry.getValue());
|
||||
String key;
|
||||
Iterator keys = jo.keys();
|
||||
while(keys.hasNext()) {
|
||||
key = keys.next().toString();
|
||||
jExtras.put(key, jo.getString(key));
|
||||
}
|
||||
jExtras.put("cn.jpush.android.EXTRA", jo);
|
||||
} else {
|
||||
jExtras.put(entry.getKey(), entry.getValue());
|
||||
@@ -176,11 +191,11 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
return data;
|
||||
}
|
||||
|
||||
static void transmitPush(String message, Map<String, Object> extras) {
|
||||
static void transmitMessageReceive(String message, Map<String, Object> extras) {
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
JSONObject data = notificationObject(message, extras);
|
||||
JSONObject data = getMessageObject(message, extras);
|
||||
String format = "window.plugins.jPushPlugin.receiveMessageInAndroidCallback(%s);";
|
||||
final String js = String.format(format, data.toString());
|
||||
cordovaActivity.runOnUiThread(new Runnable() {
|
||||
@@ -191,14 +206,12 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
});
|
||||
}
|
||||
|
||||
static void transmitOpen(String alert, Map<String, Object> extras) {
|
||||
static void transmitNotificationOpen(String title, String alert,
|
||||
Map<String, Object> extras) {
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
if (JPushPlugin.shouldCacheMsg) {
|
||||
return;
|
||||
}
|
||||
JSONObject data = openNotificationObject(alert, extras);
|
||||
JSONObject data = getNotificationObject(title, alert, extras);
|
||||
String format = "window.plugins.jPushPlugin.openNotificationInAndroidCallback(%s);";
|
||||
final String js = String.format(format, data.toString());
|
||||
cordovaActivity.runOnUiThread(new Runnable() {
|
||||
@@ -207,14 +220,16 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
instance.webView.loadUrl("javascript:" + js);
|
||||
}
|
||||
});
|
||||
JPushPlugin.openNotificationTitle = null;
|
||||
JPushPlugin.openNotificationAlert = null;
|
||||
}
|
||||
|
||||
static void transmitReceive(String alert, Map<String, Object> extras) {
|
||||
static void transmitNotificationReceive(String title, String alert,
|
||||
Map<String, Object> extras) {
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
JSONObject data = openNotificationObject(alert, extras);
|
||||
JSONObject data = getNotificationObject(title, alert, extras);
|
||||
String format = "window.plugins.jPushPlugin.receiveNotificationInAndroidCallback(%s);";
|
||||
final String js = String.format(format, data.toString());
|
||||
cordovaActivity.runOnUiThread(new Runnable() {
|
||||
@@ -223,6 +238,7 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
instance.webView.loadUrl("javascript:" + js);
|
||||
}
|
||||
});
|
||||
JPushPlugin.notificationTitle = null;
|
||||
JPushPlugin.notificationAlert = null;
|
||||
}
|
||||
|
||||
@@ -249,7 +265,6 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
|
||||
void init(JSONArray data, CallbackContext callbackContext) {
|
||||
JPushInterface.init(cordovaActivity.getApplicationContext());
|
||||
//callbackContext.success();
|
||||
}
|
||||
|
||||
void setDebugMode(JSONArray data, CallbackContext callbackContext) {
|
||||
@@ -393,24 +408,6 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
// void getNotification(JSONArray data, CallbackContext callBackContext) {
|
||||
// String alert = JPushPlugin.notificationAlert;
|
||||
// Map<String, String> extras = JPushPlugin.notificationExtras;
|
||||
//
|
||||
// JSONObject jsonData = new JSONObject();
|
||||
// try {
|
||||
// jsonData.put("message", alert);
|
||||
// jsonData.put("extras", new JSONObject(extras));
|
||||
// } catch (JSONException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// callBackContext.success(jsonData);
|
||||
//
|
||||
// JPushPlugin.notificationAlert = "";
|
||||
// JPushPlugin.notificationExtras = new HashMap<String, Obl>();
|
||||
// }
|
||||
|
||||
void setBasicPushNotificationBuilder(JSONArray data,
|
||||
CallbackContext callbackContext) {
|
||||
BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(
|
||||
@@ -423,7 +420,6 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//callbackContext.success(obj);
|
||||
}
|
||||
|
||||
void setCustomPushNotificationBuilder(JSONArray data,
|
||||
@@ -440,12 +436,10 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//callbackContext.success(obj);
|
||||
}
|
||||
|
||||
void clearAllNotification(JSONArray data, CallbackContext callbackContext) {
|
||||
JPushInterface.clearAllNotifications(cordovaActivity);
|
||||
//callbackContext.success();
|
||||
}
|
||||
|
||||
void clearNotificationById(JSONArray data, CallbackContext callbackContext) {
|
||||
@@ -465,13 +459,16 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
|
||||
void addLocalNotification(JSONArray data, CallbackContext callbackContext)
|
||||
throws JSONException {
|
||||
//builderId,content,title,notificaitonID,broadcastTime,extras
|
||||
int builderId = data.getInt(0);
|
||||
String content = data.getString(1);
|
||||
String title = data.getString(2);
|
||||
int notificationID = data.getInt(3);
|
||||
int broadcastTime = data.getInt(4);
|
||||
JSONObject extras = data.getJSONObject(5);
|
||||
String extrasStr = data.isNull(5) ? "" : data.getString(5);
|
||||
JSONObject extras = new JSONObject();
|
||||
if (!extrasStr.isEmpty()) {
|
||||
extras = new JSONObject(extrasStr);
|
||||
}
|
||||
|
||||
JPushLocalNotification ln = new JPushLocalNotification();
|
||||
ln.setBuilderId(builderId);
|
||||
@@ -479,8 +476,8 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
ln.setTitle(title);
|
||||
ln.setNotificationId(notificationID);
|
||||
ln.setBroadcastTime(System.currentTimeMillis() + broadcastTime);
|
||||
|
||||
ln.setExtras(extras.toString());
|
||||
|
||||
JPushInterface.addLocalNotification(cordovaActivity, ln);
|
||||
}
|
||||
|
||||
@@ -496,8 +493,6 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
|
||||
/**
|
||||
* 决定是否启用统计分析功能。
|
||||
* @param data
|
||||
* @param callbackContext
|
||||
*/
|
||||
void setStatisticsOpen(JSONArray data, CallbackContext callbackContext) {
|
||||
try {
|
||||
@@ -507,6 +502,48 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置通知静默时间
|
||||
* http://docs.jpush.io/client/android_api/#api_5
|
||||
*/
|
||||
void setSilenceTime(JSONArray data, CallbackContext callbackContext) {
|
||||
try {
|
||||
int startHour = data.getInt(0);
|
||||
int startMinute = data.getInt(1);
|
||||
int endHour = data.getInt(2);
|
||||
int endMinute = data.getInt(3);
|
||||
if (!isValidHour(startHour) || !isValidMinute(startMinute)) {
|
||||
callbackContext.error("开始时间数值错误");
|
||||
return;
|
||||
}
|
||||
if(!isValidHour(endHour) || !isValidMinute(endMinute)) {
|
||||
callbackContext.error("结束时间数值错误");
|
||||
return;
|
||||
}
|
||||
JPushInterface.setSilenceTime(cordovaActivity, startHour, startMinute,
|
||||
endHour, endMinute);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
callbackContext.error("error: reading json data.");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isValidHour(int hour) {
|
||||
return !(hour < 0 || hour > 23);
|
||||
}
|
||||
|
||||
private boolean isValidMinute(int minute) {
|
||||
return !(minute < 0 || minute > 59);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于 Android 6.0 以上系统申请权限,具体可参考:
|
||||
* http://docs.Push.io/client/android_api/#android-60
|
||||
*/
|
||||
void requestPermission(JSONArray data, CallbackContext callbackContext) {
|
||||
JPushInterface.requestPermission(cordovaActivity);
|
||||
}
|
||||
|
||||
private final TagAliasCallback mTagWithAliasCallback = new TagAliasCallback() {
|
||||
@Override
|
||||
public void gotResult(int code, String alias, Set<String> tags) {
|
||||
|
||||
@@ -25,7 +25,7 @@ public class MyReceiver extends BroadcastReceiver {
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(action)) {
|
||||
handlingReceivedMessage(intent);
|
||||
handlingMessageReceive(intent);
|
||||
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(action)) {
|
||||
handlingNotificationReceive(context, intent);
|
||||
} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(action)) {
|
||||
@@ -35,22 +35,25 @@ public class MyReceiver extends BroadcastReceiver {
|
||||
}
|
||||
}
|
||||
|
||||
private void handlingReceivedMessage(Intent intent) {
|
||||
private void handlingMessageReceive(Intent intent) {
|
||||
String msg = intent.getStringExtra(JPushInterface.EXTRA_MESSAGE);
|
||||
Map<String, Object> extras = getNotificationExtras(intent);
|
||||
JPushPlugin.transmitPush(msg, extras);
|
||||
JPushPlugin.transmitMessageReceive(msg, extras);
|
||||
}
|
||||
|
||||
private void handlingNotificationOpen(Context context, Intent intent) {
|
||||
Log.i(TAG, "---------------- handlingNotificationOpen");
|
||||
|
||||
String title = intent.getStringExtra(JPushInterface.EXTRA_NOTIFICATION_TITLE);
|
||||
JPushPlugin.openNotificationTitle = title;
|
||||
|
||||
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
|
||||
JPushPlugin.openNotificationAlert = alert;
|
||||
|
||||
Map<String, Object> extras = getNotificationExtras(intent);
|
||||
JPushPlugin.openNotificationExtras = extras;
|
||||
|
||||
JPushPlugin.transmitOpen(alert, extras);
|
||||
JPushPlugin.transmitNotificationOpen(title, alert, extras);
|
||||
|
||||
Intent launch = context.getPackageManager().getLaunchIntentForPackage(
|
||||
context.getPackageName());
|
||||
@@ -62,24 +65,27 @@ public class MyReceiver extends BroadcastReceiver {
|
||||
private void handlingNotificationReceive(Context context, Intent intent) {
|
||||
Log.i(TAG, "---------------- handlingNotificationReceive");
|
||||
|
||||
Intent launch = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
||||
Intent launch = context.getPackageManager().getLaunchIntentForPackage(
|
||||
context.getPackageName());
|
||||
launch.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
|
||||
String title = intent.getStringExtra(JPushInterface.EXTRA_NOTIFICATION_TITLE);
|
||||
JPushPlugin.notificationTitle = title;
|
||||
|
||||
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
|
||||
JPushPlugin.notificationAlert = alert;
|
||||
|
||||
Map<String, Object> extras = getNotificationExtras(intent);
|
||||
JPushPlugin.notificationExtras = extras;
|
||||
|
||||
JPushPlugin.transmitReceive(alert, extras);
|
||||
JPushPlugin.transmitNotificationReceive(title, alert, extras);
|
||||
}
|
||||
|
||||
private Map<String, Object> getNotificationExtras(Intent intent) {
|
||||
Map<String, Object> extrasMap = new HashMap<String, Object>();
|
||||
for (String key : intent.getExtras().keySet()) {
|
||||
if (!IGNORED_EXTRAS_KEYS.contains(key)) {
|
||||
Log.e("key", "key:" + key);
|
||||
if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) {
|
||||
extrasMap.put(key, intent.getIntExtra(key, 0));
|
||||
} else {
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -9,30 +9,20 @@
|
||||
#import "AppDelegate+JPush.h"
|
||||
#import "JPushPlugin.h"
|
||||
#import "JPUSHService.h"
|
||||
#import <objc/runtime.h>
|
||||
|
||||
@implementation AppDelegate (JPush)
|
||||
|
||||
+(void)load{
|
||||
Method origin;
|
||||
Method swizzle;
|
||||
origin=class_getInstanceMethod([self class],@selector(init));
|
||||
swizzle=class_getInstanceMethod([self class], @selector(init_plus));
|
||||
method_exchangeImplementations(origin, swizzle);
|
||||
}
|
||||
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
|
||||
[JPushPlugin setLaunchOptions:launchOptions];
|
||||
|
||||
-(instancetype)init_plus{
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(applicationDidLaunch:)
|
||||
name:@"UIApplicationDidFinishLaunchingNotification"
|
||||
object:nil];
|
||||
return [self init_plus];
|
||||
}
|
||||
|
||||
-(void)applicationDidLaunch:(NSNotification*)notification{
|
||||
if (notification) {
|
||||
[JPushPlugin setLaunchOptions:notification.userInfo];
|
||||
}
|
||||
//cordova didFinishLaunchingWithOptions
|
||||
CGRect screenBounds = [[UIScreen mainScreen] bounds];
|
||||
self.window = [[UIWindow alloc] initWithFrame:screenBounds];
|
||||
self.viewController = [[CDVViewController alloc] init];
|
||||
self.window.rootViewController = self.viewController;
|
||||
self.window.autoresizesSubviews = YES;
|
||||
[self.window makeKeyAndVisible];
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
||||
|
||||
+92
-82
@@ -27,38 +27,42 @@ JPushPlugin.prototype.call_native = function(name, args, callback) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
//public plugin function
|
||||
|
||||
JPushPlugin.prototype.startLogPageView = function(pageName) {
|
||||
// public methods
|
||||
JPushPlugin.prototype.init = function() {
|
||||
if(this.isPlatformIOS()) {
|
||||
this.call_native("startLogPageView", [pageName], null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.stopLogPageView = function(pageName) {
|
||||
if(this.isPlatformIOS()) {
|
||||
this.call_native("stopLogPageView", [pageName], null);
|
||||
var data = [];
|
||||
this.call_native("initial", data, null);
|
||||
} else {
|
||||
data = [];
|
||||
this.call_native("init", data, null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.beginLogPageView = function(pageName, duration) {
|
||||
if(this.isPlatformIOS()) {
|
||||
this.call_native("beginLogPageView", [pageName, duration], null);
|
||||
JPushPlugin.prototype.getRegistrationID = function(callback) {
|
||||
try {
|
||||
var data = [];
|
||||
this.call_native("getRegistrationID", [data], callback);
|
||||
} catch(exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setApplicationIconBadgeNumber = function(badge) {
|
||||
if(this.isPlatformIOS()) {
|
||||
this.call_native("setApplicationIconBadgeNumber", [badge], null);
|
||||
}
|
||||
JPushPlugin.prototype.stopPush = function() {
|
||||
data = [];
|
||||
this.call_native("stopPush", data, null);
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.getApplicationIconBadgeNumber = function(callback) {
|
||||
if(this.isPlatformIOS()) {
|
||||
this.call_native("getApplicationIconBadgeNumber", [], callback);
|
||||
}
|
||||
JPushPlugin.prototype.resumePush = function() {
|
||||
data = [];
|
||||
this.call_native("resumePush", data, null);
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.isPushStopped = function(callback) {
|
||||
data = [];
|
||||
this.call_native("isPushStopped", data, callback);
|
||||
}
|
||||
|
||||
// iOS methods
|
||||
JPushPlugin.prototype.setTagsWithAlias = function(tags, alias) {
|
||||
try {
|
||||
if(tags == null) {
|
||||
@@ -93,15 +97,6 @@ JPushPlugin.prototype.setAlias = function(alias) {
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.getRegistrationID = function(callback) {
|
||||
try {
|
||||
var data = [];
|
||||
this.call_native("getRegistrationID", [data], callback);
|
||||
} catch(exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setBadge = function(value) {
|
||||
if(this.isPlatformIOS()) {
|
||||
try {
|
||||
@@ -185,6 +180,57 @@ JPushPlugin.prototype.receiveMessageIniOSCallback = function(data) {
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.startLogPageView = function(pageName) {
|
||||
if(this.isPlatformIOS()) {
|
||||
this.call_native("startLogPageView", [pageName], null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.stopLogPageView = function(pageName) {
|
||||
if(this.isPlatformIOS()) {
|
||||
this.call_native("stopLogPageView", [pageName], null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.beginLogPageView = function(pageName, duration) {
|
||||
if(this.isPlatformIOS()) {
|
||||
this.call_native("beginLogPageView", [pageName, duration], null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setApplicationIconBadgeNumber = function(badge) {
|
||||
if(this.isPlatformIOS()) {
|
||||
this.call_native("setApplicationIconBadgeNumber", [badge], null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.getApplicationIconBadgeNumber = function(callback) {
|
||||
if(this.isPlatformIOS()) {
|
||||
this.call_native("getApplicationIconBadgeNumber", [], callback);
|
||||
}
|
||||
}
|
||||
|
||||
// Android methods
|
||||
JPushPlugin.prototype.setDebugMode = function(mode) {
|
||||
if(device.platform == "Android") {
|
||||
this.call_native("setDebugMode", [mode], null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setBasicPushNotificationBuilder = function() {
|
||||
if(device.platform == "Android") {
|
||||
data = [];
|
||||
this.call_native("setBasicPushNotificationBuilder", data, null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setCustomPushNotificationBuilder = function() {
|
||||
if(device.platform == "Android") {
|
||||
data = [];
|
||||
this.call_native("setCustomPushNotificationBuilder", data, null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.receiveMessageInAndroidCallback = function(data) {
|
||||
try {
|
||||
console.log("JPushPlugin:receiveMessageInAndroidCallback");
|
||||
@@ -221,39 +267,6 @@ JPushPlugin.prototype.receiveNotificationInAndroidCallback = function(data) {
|
||||
}
|
||||
}
|
||||
|
||||
//android single
|
||||
|
||||
JPushPlugin.prototype.setBasicPushNotificationBuilder = function() {
|
||||
if(device.platform == "Android") {
|
||||
data = [];
|
||||
this.call_native("setBasicPushNotificationBuilder", data, null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setCustomPushNotificationBuilder = function() {
|
||||
if(device.platform == "Android") {
|
||||
data = [];
|
||||
this.call_native("setCustomPushNotificationBuilder", data, null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.stopPush = function() {
|
||||
data = [];
|
||||
this.call_native("stopPush", data, null);
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.resumePush = function() {
|
||||
data = [];
|
||||
this.call_native("resumePush", data, null);
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setDebugMode = function(mode) {
|
||||
if(device.platform == "Android") {
|
||||
this.call_native("setDebugMode", [mode], null);
|
||||
}
|
||||
}
|
||||
|
||||
//setDebugMode
|
||||
JPushPlugin.prototype.clearAllNotification = function() {
|
||||
if(device.platform == "Android") {
|
||||
data = [];
|
||||
@@ -274,21 +287,6 @@ JPushPlugin.prototype.setLatestNotificationNum = function(num) {
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.isPushStopped = function(callback) {
|
||||
data = [];
|
||||
this.call_native("isPushStopped", data, callback);
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.init = function() {
|
||||
if(this.isPlatformIOS()) {
|
||||
var data = [];
|
||||
this.call_native("initial", data, null);
|
||||
} else {
|
||||
data = [];
|
||||
this.call_native("init", data, null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setDebugMode = function(mode) {
|
||||
if(device.platform == "Android") {
|
||||
this.call_native("setDebugMode", [mode], null);
|
||||
@@ -296,9 +294,9 @@ JPushPlugin.prototype.setDebugMode = function(mode) {
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.addLocalNotification = function(builderId, content, title,
|
||||
notificaitonID, broadcastTime, extras) {
|
||||
notificationID, broadcastTime, extras) {
|
||||
if(device.platform == "Android") {
|
||||
data = [builderId, content, title, notificaitonID, broadcastTime, extras];
|
||||
data = [builderId, content, title, notificationID, broadcastTime, extras];
|
||||
this.call_native("addLocalNotification", data, null);
|
||||
}
|
||||
}
|
||||
@@ -325,14 +323,26 @@ JPushPlugin.prototype.reportNotificationOpened = function(msgID) {
|
||||
/**
|
||||
*是否开启统计分析功能,用于“用户使用时长”,“活跃用户”,“用户打开次数”的统计,并上报到服务器上,
|
||||
*在 Portal 上展示给开发者。
|
||||
**/
|
||||
*/
|
||||
JPushPlugin.prototype.setStatisticsOpen = function(mode) {
|
||||
if(device.platform == "Android") {
|
||||
this.call_native("setStatisticsOpen", [mode], null);
|
||||
}
|
||||
}
|
||||
|
||||
//iOS single
|
||||
/**
|
||||
* 用于在 Android 6.0 及以上系统,申请一些权限
|
||||
* 具体可看:http://docs.jpush.io/client/android_api/#android-60
|
||||
*/
|
||||
JPushPlugin.prototype.requestPermission = function() {
|
||||
if(device.platform == "Android") {
|
||||
this.call_native("requestPermission", [], null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setSilenceTime = function() {
|
||||
|
||||
}
|
||||
|
||||
if(!window.plugins) {
|
||||
window.plugins = {};
|
||||
|
||||
Reference in New Issue
Block a user