mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2026-02-08 00:05:13 +08:00
Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
adb385a90b | ||
|
|
76b3014417 | ||
|
|
5fb1a440c4 | ||
|
|
4edee3e2d3 | ||
|
|
1a6800a7b4 | ||
|
|
95c9b12124 | ||
|
|
e11b80f80c | ||
|
|
d1e4f70188 | ||
|
|
8241b364cc | ||
|
|
706f32a972 | ||
|
|
c64304e632 | ||
|
|
c9cb88b9ef | ||
|
|
f177e8ae46 | ||
|
|
d4e9eb9b67 | ||
|
|
eb1fc6ef13 | ||
|
|
b698a2bfd3 | ||
|
|
3bd75e0799 | ||
|
|
404f19037e | ||
|
|
b02e3faef0 | ||
|
|
8b481ddd92 | ||
|
|
a599a02a14 | ||
|
|
84da6e065e | ||
|
|
15dee5cd1c | ||
|
|
87da25a8f2 | ||
|
|
20cd9b0964 | ||
|
|
560e1bb9bd | ||
|
|
d208306884 | ||
|
|
cd9ca28ba8 |
4
.travis.yml
Normal file
4
.travis.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
language: node_js
|
||||
sudo: false
|
||||
node_js:
|
||||
- "4.2"
|
||||
263
API/Android_detail_api.md
Normal file
263
API/Android_detail_api.md
Normal file
@@ -0,0 +1,263 @@
|
||||
# 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.receiveMessage.message
|
||||
- 附加字段:
|
||||
window.plugins.jPushPlugin.receiveMessage.extras.yourKey
|
||||
|
||||
## 获取集成日志
|
||||
|
||||
### API - setDebugMode
|
||||
|
||||
用于开启调试模式,可以查看集成 JPush 过程中的 Log,如果集成失败,可方便定位问题所在。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setDebugMode(mode)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- mode:
|
||||
- true 显示集成日志。
|
||||
- false 不显示集成日志。
|
||||
|
||||
|
||||
## 接收消息和点击通知事件
|
||||
### API - receiveMessageInAndroidCallback
|
||||
|
||||
用于 Android 收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.receiveMessageInAndroidCallback(data)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- data: 接收到的 js 字符串,包含的 key:value 请进入该函数体查看。
|
||||
|
||||
|
||||
### API - openNotificationInAndroidCallback
|
||||
|
||||
当点击 Android 手机的通知栏进入应用程序时,会调用这个函数,这个函数不需要主动调用,是作为回调函数来用的。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.openNotificationInAndroidCallback(data)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- data: js 字符串。
|
||||
|
||||
|
||||
## 统计分析
|
||||
|
||||
### API - onResume / onPause
|
||||
|
||||
这是一个 Android Local API,不是 js 的 API,请注意。
|
||||
本 API 用于“用户使用时长”,“活跃用户”,“用户打开次数”的统计,并上报到服务器,在 Portal 上展示给开发者。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
public static void onResume(final Activity activity)
|
||||
public static void onPause(final Activity activity)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- Activity: 当前所在的 Activity。
|
||||
|
||||
#### 调用说明
|
||||
|
||||
应在所有的 Activity 的 onResume / onPause 方法里调用。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
JPushInterface.onResume(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
JPushInterface.onPause(this);
|
||||
}
|
||||
|
||||
### API - setStatisticsOpen
|
||||
|
||||
用于在 js 中控制是否打开应用的统计分析功能,但如果已经添加了上面的 onResume / onPause 方法,
|
||||
就不能再通过这个方法来控制统计分析功能了。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setStatisticsOpen(boolean)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- boolean:
|
||||
- true: 打开统计分析功能。
|
||||
- false: 关闭统计分析功能。
|
||||
|
||||
### API - reportNotificationOpened
|
||||
|
||||
用于上报用户的通知栏被打开,或者用于上报用户自定义消息被展示等客户端需要统计的事件。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.reportNotificationOpened(msgID)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- msgID: 收到的通知或者自定义消息的 id。
|
||||
|
||||
|
||||
## 清除通知
|
||||
|
||||
### API - clearAllNotification
|
||||
|
||||
推送通知到客户端时,由 JPush SDK 展现通知到通知栏上。
|
||||
|
||||
此 API 提供清除通知的功能,包括:清除所有 JPush 展现的通知(不包括非 JPush SDK 展现的)。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.clearAllNotification()
|
||||
|
||||
|
||||
## 设置允许推送时间
|
||||
|
||||
### API - setPushTime
|
||||
默认情况下用户在任何时间都允许推送。即任何时候有推送下来,客户端都会收到,并展示。
|
||||
开发者可以调用此 API 来设置允许推送的时间。
|
||||
如果不在该时间段内收到消息,当前的行为是:推送到的通知会被扔掉。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setPushTime(days, startHour, endHour)
|
||||
|
||||
#### 参数说明
|
||||
- days: 数组,0 表示星期天,1 表示星期一,以此类推(7天制,数组中值的范围为 0 到 6 )。
|
||||
数组的值为 null, 表示任何时间都可以收到消息和通知,数组的 size 为 0,则表示任何时间都收不到消息和通知。
|
||||
- startHour: 整形,允许推送的开始时间 (24 小时制:startHour 的范围为 0 到 23)。
|
||||
- endHour: 整形,允许推送的结束时间 (24 小时制:endHour 的范围为 0 到 23)。
|
||||
|
||||
## 设置通知静默时间
|
||||
|
||||
### API - setSilenceTime
|
||||
默认情况下用户在收到推送通知时,客户端可能会有震动,响铃等提示。
|
||||
但用户在睡觉、开会等时间点希望为 "免打扰" 模式,也是静音时段的概念。
|
||||
开发者可以调用此 API 来设置静音时段。如果在该时间段内收到消息,则:不会有铃声和震动。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setSilenceTime(startHour, startMinute, endHour, endMinute)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- startHour: 整形,静音时段的开始时间 - 小时 (24小时制,范围:0~23 )。
|
||||
- startMinute: 整形,静音时段的开始时间 - 分钟(范围:0~59 )。
|
||||
- endHour: 整形,静音时段的结束时间 - 小时 (24小时制,范围:0~23 )。
|
||||
- endMinute: 整形,静音时段的结束时间 - 分钟(范围:0~59 )。
|
||||
|
||||
|
||||
## 通知栏样式定制
|
||||
|
||||
### API - setBasicPushNotificationBuilder, setCustomPushNotificationBuilder
|
||||
|
||||
当用户需要定制默认的通知栏样式时,则可调用此方法。
|
||||
需要用户去自定义 ../JPushPlugin.java 中的同名方法代码,然后再在 js 端 调用该方法。
|
||||
|
||||
具体用法可参考[官方文档](http://docs.jpush.io/client/android_tutorials/#_11)。
|
||||
|
||||
JPush SDK 提供了 2 个用于定制通知栏样式的构建类:
|
||||
|
||||
- setBasicPushNotificationBuilder:
|
||||
Basic 用于定制 Android Notification 里的 defaults / flags / icon 等基础样式(行为)。
|
||||
- setCustomPushNotificationBuilder:
|
||||
继承 Basic 进一步让开发者定制 Notification Layout。
|
||||
|
||||
如果不调用此方法定制,则极光 Push SDK 默认的通知栏样式是 Android 标准的通知栏。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setBasicPushNotificationBuilder()
|
||||
window.plugins.jPushPlugin.setCustomPushNotificationBuilder()
|
||||
|
||||
|
||||
## 设置保留最近通知条数
|
||||
|
||||
### API - setLatestNotificationNum
|
||||
|
||||
通过极光推送,推送了很多通知到客户端时,如果用户不去处理,就会有很多保留在那里。
|
||||
|
||||
默认为保留最近 5 条通知,开发者可通过调用此 API 来定义为不同的数量。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setLatestNotificationNum(num)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- num: 保存的条数。
|
||||
|
||||
|
||||
## 本地通知
|
||||
### API - addLocalNotification, removeLocalNotification, clearLocalNotifications
|
||||
|
||||
本地通知 API 不依赖于网络,无网条件下依旧可以触发。
|
||||
|
||||
本地通知与网络推送的通知是相互独立的,不受保留最近通知条数上限的限制。
|
||||
|
||||
本地通知的定时时间是自发送时算起的,不受中间关机等操作的影响。
|
||||
|
||||
三个接口的功能分别为:添加一个本地通知,删除一个本地通知,删除所有的本地通知。
|
||||
|
||||
#####接口定义
|
||||
|
||||
window.plugins.jPushPlugin.addLocalNotification(builderId, content, title,
|
||||
notificaitonID, broadcastTime, extras)
|
||||
window.plugins.jPushPlugin.removeLocalNotification(notificationID)
|
||||
window.plugins.jPushPlugin.clearLocalNotifications()
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- builderId: 设置本地通知样式。
|
||||
- content: 设置本地通知的 content。
|
||||
- title: 设置本地通知的 title。
|
||||
- notificaitonID: 设置本地通知的 ID。
|
||||
- broadcastTime: 设置本地通知触发时间,为距离当前时间的数值,单位是毫秒。
|
||||
- extras: 设置额外的数据信息 extras 为 json 字符串。
|
||||
372
API/Common_detail_api.md
Normal file
372
API/Common_detail_api.md
Normal file
@@ -0,0 +1,372 @@
|
||||
# 通用 API 说明
|
||||
|
||||
- [停止与恢复推送服务](#停止与恢复推送服务)
|
||||
- [获取 RegistrationID](#获取-registrationid)
|
||||
- [设置别名与标签](#设置别名与标签)
|
||||
- [获取点击通知内容](#获取点击通知内容)
|
||||
- [获取通知内容](#获取通知内容)
|
||||
- [获取自定义消息推送内容](#获取自定义消息推送内容)
|
||||
|
||||
|
||||
## 停止与恢复推送服务
|
||||
### API - init
|
||||
|
||||
调用此 API,用来开启 JPush SDK 提供的推送服务。
|
||||
|
||||
开发者 App 可以通过调用停止推送服务 API 来停止极光推送服务。当又需要使用极光推送服务时,则必须要调用恢复推送服务 API。
|
||||
|
||||
本功能是一个完全本地的状态操作,也就是说:停止推送服务的状态不会保存到服务器上。
|
||||
|
||||
如果停止推送服务后,开发者 App 被重新安装,或者被清除数据,
|
||||
JPush SDK 会恢复正常的默认行为。(因为保存在本地的状态数据被清除掉了)。
|
||||
|
||||
本功能其行为类似于网络中断的效果,即:推送服务停止期间推送的消息,
|
||||
恢复推送服务后,如果推送的消息还在保留的时长范围内,则客户端是会收到离线消息。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.init()
|
||||
|
||||
### API - stopPush
|
||||
+ Android 平台:
|
||||
|
||||
+ 开发者 App 可以通过调用停止推送服务 API 来停止极光推送服务,当又需要使用极光推送服务时,则必须要调用恢复推送服务 API。
|
||||
|
||||
+ 调用了本 API 后,JPush 推送服务完全被停止,具体表现为:
|
||||
|
||||
+ JPush Service 不在后台运行。
|
||||
+ 收不到推送消息。
|
||||
+ 不能通过 JPushInterface.init 恢复,需要调用 resumePush 恢复。
|
||||
+ 极光推送所有的其他 API 调用都无效。
|
||||
|
||||
+ iOS 平台:
|
||||
|
||||
+ 不推荐调用,因为这个 API 只是让你的 DeviceToken 失效,在 设置-通知 中您的应用程序没有任何变化。
|
||||
+ 推荐:设置一个 UI 界面, 提醒用户在 设置-通知 中关闭推送服务。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.stopPush()
|
||||
|
||||
|
||||
### API - resumePush
|
||||
|
||||
恢复推送服务。调用了此 API 后:
|
||||
|
||||
+ Android 平台:
|
||||
|
||||
+ 极光推送完全恢复正常工作。
|
||||
|
||||
+ iOS 平台:
|
||||
|
||||
+ 重新去APNS注册。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.resumePush()
|
||||
|
||||
### API - isPushStopped
|
||||
|
||||
+ Android 平台:
|
||||
|
||||
+ 用来检查 Push Service 是否已经被停止。
|
||||
|
||||
+ iOS 平台:
|
||||
|
||||
+ 平台检查推送服务是否注册。
|
||||
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.isPushStopped(callback)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
+ callback: 回调函数,用来通知 JPush 的推送服务是否开启。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.resumePush(callback)
|
||||
var onCallback = function(data) {
|
||||
if(data > 0) {
|
||||
// 开启
|
||||
} else {
|
||||
// 关闭
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
## 获取 RegistrationID
|
||||
|
||||
### API - getRegistrationID
|
||||
|
||||
RegistrationID 定义:
|
||||
|
||||
集成了 JPush SDK 的应用程序在第一次成功注册到 JPush 服务器时,JPush 服务器会给客户端返回一个唯一的该设备的标识 - RegistrationID。
|
||||
JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
|
||||
|
||||
应用程序可以把此 RegistrationID 保存以自己的应用服务器上,然后就可以根据 RegistrationID 来向设备推送消息或者通知。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
JPushPlugin.prototype.getRegistrationID(callback)
|
||||
|
||||
#### 返回值
|
||||
|
||||
调用此 API 来取得应用程序对应的 RegistrationID。 只有当应用程序成功注册到 JPush 的服务器时才返回对应的值,否则返回空字符串。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
|
||||
var onGetRegistradionID = function(data) {
|
||||
try {
|
||||
console.log("JPushPlugin:registrationID is " + data);
|
||||
} catch(exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
|
||||
## 设置别名与标签
|
||||
|
||||
### API - setTagsWithAlias, setTags, setAlias
|
||||
|
||||
提供几个相关 API 用来设置别名(alias)与标签(tags)。
|
||||
|
||||
这几个 API 可以在 App 里任何地方调用。
|
||||
|
||||
**别名 Alias**:
|
||||
|
||||
为安装了应用程序的用户,取个别名来标识。以后给该用户 Push 消息时,就可以用此别名来指定。
|
||||
|
||||
每个用户只能指定一个别名。
|
||||
|
||||
同一个应用程序内,对不同的用户,建议取不同的别名。这样,尽可能根据别名来唯一确定用户。
|
||||
|
||||
系统不限定一个别名只能指定一个用户。如果一个别名被指定到了多个用户,当给指定这个别名发消息时,服务器端 API 会同时给这多个用户发送消息。
|
||||
|
||||
举例:在一个用户要登录的游戏中,可能设置别名为 userid。游戏运营时,发现该用户 3 天没有玩游戏了,则根据 userid 调用服务器端 API 发通知到客户端提醒用户。
|
||||
|
||||
**标签 Tag**:
|
||||
|
||||
为安装了应用程序的用户,打上标签。其目的主要是方便开发者根据标签,来批量下发 Push 消息。
|
||||
|
||||
可为每个用户打多个标签。
|
||||
|
||||
不同应用程序、不同的用户,可以打同样的标签。
|
||||
|
||||
举例: game, old_page, women。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
JPushPlugin.prototype.setTagsWithAlias(tags, alias)
|
||||
JPushPlugin.prototype.setTags(tags)
|
||||
JPushPlugin.prototype.setAlias(alias)
|
||||
|
||||
#### 参数说明
|
||||
* tags:
|
||||
* 参数类型为数组。
|
||||
* nil 此次调用不设置此值。
|
||||
* 空集合表示取消之前的设置。
|
||||
* 每次调用至少设置一个 tag,覆盖之前的设置,不是新增。
|
||||
* 有效的标签组成:字母(区分大小写)、数字、下划线、汉字。
|
||||
* 限制:每个 tag 命名长度限制为 40 字节,最多支持设置 100 个 tag,但总长度不得超过1K字节(判断长度需采用 UTF-8 编码)。
|
||||
* 单个设备最多支持设置 100 个 tag,App 全局 tag 数量无限制。
|
||||
* alias:
|
||||
* 参数类型为字符串。
|
||||
* nil 此次调用不设置此值。
|
||||
* 空字符串 ("")表示取消之前的设置。
|
||||
* 有效的别名组成:字母(区分大小写)、数字、下划线、汉字。
|
||||
* 限制:alias 命名长度限制为 40 字节(判断长度需采用 UTF-8 编码)。
|
||||
|
||||
#### 返回值说明
|
||||
|
||||
函数本身无返回值,但需要注册 `jpush.setTagsWithAlias` 事件来监听设置结果:
|
||||
|
||||
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
|
||||
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) {
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
|
||||
#### 错误码定义
|
||||
|
||||
|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 次。 |短时间内操作过于频繁。|
|
||||
|
||||
|
||||
## 获取点击通知内容
|
||||
|
||||
### 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.openNotification,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意。
|
||||
|
||||
+ Android:
|
||||
|
||||
{
|
||||
"title": "title",
|
||||
"alert":"ding",
|
||||
"extras":{
|
||||
"yourKey": "yourValue",
|
||||
"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": "今天去哪儿"
|
||||
},
|
||||
"key1": "value1",
|
||||
"key2": "value2",
|
||||
"_j_msgid": 154604475
|
||||
}
|
||||
|
||||
## 获取通知内容
|
||||
|
||||
### event - jpush.receiveNotification
|
||||
|
||||
收到通知时会触发该事件。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
- 在你需要接收通知的的 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);
|
||||
|
||||
ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.receiveNotification,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意。
|
||||
|
||||
+ Android:
|
||||
|
||||
{
|
||||
"title": "title",
|
||||
"alert":"ding",
|
||||
"extras":{
|
||||
"yourKey": "yourValue",
|
||||
"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":"今天去哪儿"
|
||||
},
|
||||
"key1":"value1",
|
||||
"key2":"value2",
|
||||
"_j_msgid":154604475
|
||||
}
|
||||
|
||||
|
||||
## 获取自定义消息推送内容
|
||||
|
||||
### event - jpush.receiveMessage
|
||||
|
||||
收到自定义消息时触发这个事件,推荐使用事件的方式传递。
|
||||
|
||||
但同时保留了 receiveMessageIniOSCallback 的回调函数,兼容以前的代码。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
- 在你需要接收通知的的 js 文件中加入:
|
||||
|
||||
document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);
|
||||
|
||||
- onReceiveMessage 需要这样写:
|
||||
|
||||
var onReceiveMessage = function(event) {
|
||||
try{
|
||||
var message
|
||||
if(device.platform == "Android") {
|
||||
message = window.plugins.jPushPlugin.receiveMessage.message;
|
||||
} else {
|
||||
message = event.content;
|
||||
}
|
||||
$("#messageResult").html(message);
|
||||
} catch(exception) {
|
||||
console.log("JPushPlugin:onReceiveMessage-->" + exception);
|
||||
}
|
||||
}
|
||||
|
||||
ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.receiveMessage,
|
||||
直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意。
|
||||
|
||||
+ Android:
|
||||
|
||||
{
|
||||
"message":"今天去哪儿",
|
||||
"extras"{
|
||||
"yourKey": "yourValue",
|
||||
"cn.jpush.android.MSG_ID":"154378013",
|
||||
"cn.jpush.android.CONTENT_TYPE":"",
|
||||
"cn.jpush.android.EXTRA":{"key":"不添没有"}
|
||||
}
|
||||
}
|
||||
|
||||
+ iOS:
|
||||
|
||||
{
|
||||
"content":"今天去哪儿",
|
||||
"extras":{"key":"不填写没有"}
|
||||
}
|
||||
571
API/iOS API.md
Normal file
571
API/iOS API.md
Normal file
@@ -0,0 +1,571 @@
|
||||
# iOS API
|
||||
|
||||
- [开始与停止推送服务](#开始与停止推送服务)
|
||||
- [获取 RegistrationID](#获取-registrationid)
|
||||
- [别名与标签](#别名与标签)
|
||||
- [获取 APNS 推送内容](#获取-apns-推送内容)
|
||||
- [点击推送通知](#点击推送通知)
|
||||
- [前台收到推送](#前台收到推送)
|
||||
- [后台收到推送](#后台收到推送)
|
||||
- [获取自定义消息内容](#获取自定义消息内容)
|
||||
- [设置Badge](#设置badge)
|
||||
- [本地通知](#本地通知)
|
||||
- [页面的统计](#页面的统计)
|
||||
- [日志等级设置](#日志等级设置)
|
||||
- [地理位置上报](#地理位置上报)
|
||||
- [设备平台判断](#设备平台判断)
|
||||
|
||||
## 开始与停止推送服务
|
||||
|
||||
### API - init
|
||||
|
||||
调用此 API,用来开启 JPush SDK 提供的推送服务。
|
||||
|
||||
开发者 App 可以通过调用停止推送服务 API 来停止极光推送服务,当又需要使用极光推送服务时,则必须要调用恢复推送服务 API。
|
||||
|
||||
```
|
||||
本功能是一个完全本地的状态操作。也就是说:停止推送服务的状态不会保存到服务器上。
|
||||
如果停止推送服务后,开发者 App 被重新安装,或者被清除数据,
|
||||
JPush SDK 会恢复正常的默认行为。(因为保存在本地的状态数据被清除掉了)。
|
||||
本功能其行为类似于网络中断的效果,即:推送服务停止期间推送的消息,
|
||||
恢复推送服务后,如果推送的消息还在保留的时长范围内,则客户端是会收到离线消息。
|
||||
```
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.init()
|
||||
|
||||
|
||||
### API - stopPush
|
||||
|
||||
- 不推荐调用,因为这个 API 只是让你的 DeviceToken 失效,在 设置-通知 中您的应用程序没有任何变化。
|
||||
- 推荐:设置一个 UI 界面,提醒用户在 设置-通知 中关闭推送服务。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.stopPush()
|
||||
|
||||
|
||||
### API - resumePush
|
||||
|
||||
恢复推送服务。调用了此 API 后,iOS平台,重新去APNS注册。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.resumePush()
|
||||
|
||||
|
||||
### API - isPushStopped
|
||||
|
||||
iOS平台,检查推送服务是否注册。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.isPushStopped(callback)
|
||||
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- callback 回调函数,用来通知 JPush 的推送服务是否开启。
|
||||
|
||||
#### 代码示例
|
||||
window.plugins.jPushPlugin.resumePush(callback)
|
||||
var onCallback = function(data) {
|
||||
if(data > 0) {
|
||||
// 开启
|
||||
} else {
|
||||
// 关闭
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
## 获取 RegistrationID
|
||||
|
||||
### API - getRegistrationID
|
||||
|
||||
RegistrationID 定义:
|
||||
|
||||
集成了 JPush SDK 的应用程序在第一次成功注册到 JPush 服务器时,JPush 服务器会给客户端返回一个唯一的该设备的标识 - RegistrationID。
|
||||
JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
|
||||
|
||||
应用程序可以把此 RegistrationID 保存以自己的应用服务器上,然后就可以根据 RegistrationID 来向设备推送消息或者通知。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
JPushPlugin.prototype.getRegistrationID(callback)
|
||||
|
||||
#### 返回值
|
||||
|
||||
调用此 API 来取得应用程序对应的 RegistrationID。只有当应用程序成功注册到 JPush 的服务器时才返回对应的值,否则返回空字符串。
|
||||
|
||||
#### 调用示例
|
||||
|
||||
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
|
||||
var onGetRegistradionID = function(data) {
|
||||
try {
|
||||
console.log("JPushPlugin:registrationID is " + data);
|
||||
} catch(exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
|
||||
## 别名与标签
|
||||
|
||||
### API - setTagsWithAlias, setTags, setAlias
|
||||
|
||||
提供几个相关 API 用来设置别名(alias)与标签(tags)。
|
||||
|
||||
这几个 API 可以在 App 里任何地方调用。
|
||||
|
||||
**别名 Alias**
|
||||
|
||||
为安装了应用程序的用户,取个别名来标识。以后给该用户 Push 消息时,就可以用此别名来指定。
|
||||
|
||||
每个用户只能指定一个别名。
|
||||
|
||||
同一个应用程序内,对不同的用户,建议取不同的别名。这样,尽可能根据别名来唯一确定用户。
|
||||
|
||||
系统不限定一个别名只能指定一个用户。如果一个别名被指定到了多个用户,当给指定这个别名发消息时,服务器端 API 会同时给这多个用户发送消息。
|
||||
|
||||
举例:在一个用户要登录的游戏中,可能设置别名为 userid。游戏运营时,发现该用户 3 天没有玩游戏了,则根据 userid 调用服务器端 API 发通知到客户端提醒用户。
|
||||
|
||||
**标签 Tag**
|
||||
|
||||
为安装了应用程序的用户,打上标签。其目的主要是方便开发者根据标签,来批量下发 Push 消息。
|
||||
|
||||
可为每个用户打多个标签。
|
||||
|
||||
不同应用程序、不同的用户,可以打同样的标签。
|
||||
|
||||
举例: game, old_page, women。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
JPushPlugin.prototype.setTagsWithAlias(tags, alias)
|
||||
JPushPlugin.prototype.setTags(tags)
|
||||
JPushPlugin.prototype.setAlias(alias)
|
||||
|
||||
#### 参数说明
|
||||
* tags:
|
||||
* 参数类型为数组。
|
||||
* nil 此次调用不设置此值。
|
||||
* 空集合表示取消之前的设置。
|
||||
* 每次调用至少设置一个 tag,覆盖之前的设置,不是新增。
|
||||
* 有效的标签组成:字母(区分大小写)、数字、下划线、汉字。
|
||||
* 限制:每个 tag 命名长度限制为 40 字节,最多支持设置 100 个 tag,但总长度不得超过1K字节(判断长度需采用UTF-8编码)。
|
||||
* 单个设备最多支持设置 100 个 tag,App 全局 tag 数量无限制。
|
||||
* alias:
|
||||
* 参数类型为字符串。
|
||||
* nil 此次调用不设置此值。
|
||||
* 空字符串 ("")表示取消之前的设置。
|
||||
* 有效的别名组成:字母(区分大小写)、数字、下划线、汉字。
|
||||
* 限制:alias 命名长度限制为 40 字节(判断长度需采用 UTF-8 编码)。
|
||||
|
||||
#### 返回值说明
|
||||
|
||||
函数本身无返回值,但需要注册 `jpush.setTagsWithAlias` 事件来监听设置结果。
|
||||
|
||||
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
|
||||
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) {
|
||||
console.log(exception)
|
||||
}
|
||||
}
|
||||
|
||||
#### 错误码定义
|
||||
|
||||
|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次 |短时间内操作过于频繁。|
|
||||
|
||||
|
||||
## 获取 APNS 推送内容
|
||||
|
||||
### 点击推送通知
|
||||
|
||||
#### event - jpush.openNotification
|
||||
|
||||
点击通知启动或唤醒应用程序时会出发该事件
|
||||
|
||||
#### 代码示例
|
||||
|
||||
- 在你需要接收通知的的 js 文件中加入:
|
||||
|
||||
document.addEventListener("jpush.openNotification", onOpenNotification, false);
|
||||
|
||||
- onOpenNotification 需要这样写:
|
||||
|
||||
var onOpenNotification = function(event) {
|
||||
var alertContent;
|
||||
alertContent = event.aps.alert;
|
||||
alert("open Notificaiton:" + alertContent);
|
||||
}
|
||||
|
||||
- event 举例:
|
||||
|
||||
{
|
||||
"aps":{
|
||||
"badge":1,
|
||||
"sound":"default",
|
||||
"alert":"今天去哪儿"
|
||||
},
|
||||
"key1":"value1",
|
||||
"key2":"value2",
|
||||
"_j_msgid":154604475
|
||||
}
|
||||
|
||||
### 前台收到推送
|
||||
|
||||
#### event - jpush.receiveNotification
|
||||
|
||||
应用程序处于前台时收到推送会触发该事件
|
||||
|
||||
#### 代码示例
|
||||
|
||||
- 在你需要接收通知的的 js 文件中加入:
|
||||
|
||||
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
|
||||
|
||||
- onReceiveNotification 需要这样写:
|
||||
|
||||
var onReceiveNotification = function(event) {
|
||||
var alertContent;
|
||||
alertContent = event.aps.alert;
|
||||
alert("open Notificaiton:" + alertContent);
|
||||
}
|
||||
|
||||
- event 举例
|
||||
|
||||
{
|
||||
"aps":{
|
||||
"badge":1,
|
||||
"sound":"default",
|
||||
"alert":"今天去哪儿"
|
||||
},
|
||||
"key1":"value1",
|
||||
"key2":"value2",
|
||||
"_j_msgid":154604475
|
||||
}
|
||||
|
||||
### 后台收到推送
|
||||
|
||||
#### event - jpush.backgroundNotification
|
||||
|
||||
应用程序处于后台时收到推送会触发该事件,可以在后台执行一段代码。具体配置参考 [iOS 7 Background Remote Notification](http://docs.jpush.io/client/ios_tutorials/#ios-7-background-remote-notification)
|
||||
|
||||
#### 代码示例
|
||||
|
||||
- 在你需要接收通知的的 js 文件中加入:
|
||||
|
||||
document.addEventListener("jpush.backgroundNotification", onBackgroundNotification, false);
|
||||
|
||||
- onBackgroundNotification 需要这样写:
|
||||
|
||||
var onBackgroundNotification = function(event) {
|
||||
var alertContent;
|
||||
alertContent = event.aps.alert;
|
||||
alert("open Notificaiton:" + alertContent);
|
||||
}
|
||||
|
||||
+ event 举例
|
||||
|
||||
{
|
||||
"aps":{
|
||||
"badge":1,
|
||||
"sound":"default",
|
||||
"alert":"今天去哪儿"
|
||||
},
|
||||
"key1":"value1",
|
||||
"key2":"value2",
|
||||
"_j_msgid":154604475
|
||||
}
|
||||
|
||||
#### API - receiveMessageIniOSCallback
|
||||
|
||||
用于 iOS 收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
|
||||
不推荐使用回调函数
|
||||
|
||||
##### 接口定义
|
||||
|
||||
JPushPlugin.prototype.receiveMessageIniOSCallback(data)
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- data: 是一个 js 字符串使用如下代码解析,js 具体 key 根据应用内消息来确定:
|
||||
|
||||
var bToObj = JSON.parse(data);
|
||||
|
||||
|
||||
## 获取自定义消息内容
|
||||
|
||||
|
||||
### event - jpush.receiveMessage
|
||||
|
||||
收到应用内消息时触发这个事件, 推荐使用事件的方式传递,但同时保留了 receiveMessageIniOSCallback 的回调函数,兼容以前的代码。
|
||||
|
||||
|
||||
#### 代码示例
|
||||
|
||||
- 在你需要接收通知的的 js 文件中加入:
|
||||
|
||||
document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);
|
||||
|
||||
- onReceiveMessage 需要这样写:
|
||||
|
||||
var onReceiveMessage = function(event) {
|
||||
try{
|
||||
var message;
|
||||
message = event.content;
|
||||
$("#messageResult").html(message);
|
||||
}catch(exception) {
|
||||
console.log("JPushPlugin:onReceiveMessage-->" + exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- event 举例:
|
||||
|
||||
{
|
||||
"content":"今天去哪儿",
|
||||
"extras":
|
||||
{
|
||||
"key":"不填写没有"
|
||||
}
|
||||
}
|
||||
|
||||
## 设置Badge
|
||||
### API - setBadge, resetBadge
|
||||
|
||||
JPush 封装 badge 功能,允许应用上传 badge 值至 JPush 服务器,
|
||||
由 JPush 后台帮助管理每个用户所对应的推送 badge 值,简化了设置推送 badge 的操作。
|
||||
(本接口不会直接改变应用本地的角标值. 要修改本地 badege 值,使用 setApplicationIconBadgeNumber)
|
||||
|
||||
实际应用中,开发者可以直接对 badge 值做增减操作,无需自己维护用户与 badge 值之间的对应关系。
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.setBadge(value)
|
||||
window.plugins.jPushPlugin.prototype.reSetBadge()
|
||||
|
||||
resetBadge相当于setBadge(0)。
|
||||
|
||||
#### 参数说明
|
||||
value 取值范围:[0,99999]。
|
||||
|
||||
#### 返回值
|
||||
无,控制台会有 log 打印设置结果。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.setBadge(5);
|
||||
window.plugins.jPushPlugin.reSetBadge();
|
||||
|
||||
### API - setApplicationIconBadgeNumber
|
||||
|
||||
本接口直接改变应用本地的角标值,设置 iOS 的角标,当设置 badge = 0 时为清除角标。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.setApplicationIconBadgeNumber(badge)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- badge: 整形,例如 0,1,2(当 badge 为 0 时,角标被清除)。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
|
||||
|
||||
### API - getApplicationIconBadgeNumber
|
||||
|
||||
获取 iOS 的角标值。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.getApplicationIconBadgeNumber(callback)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- callback: 回调函数。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.getApplicationIconBadgeNumber(function(data) {
|
||||
console.log(data);
|
||||
});
|
||||
|
||||
|
||||
## 本地通知
|
||||
|
||||
### API - addLocalNotificationForIOS
|
||||
|
||||
用于注册本地通知,最多支持64个。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.addLocalNotificationForIOS(delayTime, content, badge, notificationID, extras)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- delayTime: 本地推送延迟多长时间后显示,数值类型或纯数字的字符型均可。
|
||||
- content: 本地推送需要显示的内容。
|
||||
- badge: 角标的数字。如果不需要改变角标传-1。数值类型或纯数字的字符型均可。
|
||||
- notificationID: 本地推送标识符,字符串。
|
||||
- extras: 自定义参数,可以用来标识推送和增加附加信息。字典类型。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.addLocalNotificationForIOS(6*60*60, "本地推送内容", 1, "notiId", {"key":"value"});
|
||||
|
||||
### API - deleteLocalNotificationWithIdentifierKeyInIOS
|
||||
|
||||
删除本地推送定义。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.deleteLocalNotificationWithIdentifierKeyInIOS(identifierKey)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- identifierKey: 本地推送标识符。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.deleteLocalNotificationWithIdentifierKeyInIOS("identifier");
|
||||
|
||||
### API - clearAllLocalNotifications
|
||||
|
||||
清除所有本地推送对象。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.clearAllLocalNotifications()
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.clearAllLocalNotifications();
|
||||
|
||||
|
||||
## 页面的统计
|
||||
|
||||
### API - startLogPageView, stopLogPageView, beginLogPageView
|
||||
|
||||
用于“用户指定页面使用时长”的统计,并上报到服务器,在 Portal 上展示给开发者。
|
||||
页面统计集成正确,才能够获取正确的页面访问路径、访问深度(PV)的数据。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.startLogPageView(pageName)
|
||||
window.plugins.jPushPlugin.prototype.stopLogPageView(pageName)
|
||||
window.plugins.jPushPlugin.prototype.beginLogPageView(pageName, duration)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- pageName: 需要统计页面自定义名称
|
||||
- duration: 自定义的页面时间
|
||||
|
||||
#### 调用说明
|
||||
应在所有的需要统计得页面得 viewWillAppear 和 viewWillDisappear 加入 startLogPageView 和 stopLogPageView 来统计当前页面的停留时间。
|
||||
|
||||
或者直接使用 beginLogPageView 来自定义加入页面和时间信息。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.beginLogPageView("newPage", 5);
|
||||
window.plugins.jPushPlugin.startLogPageView("onePage");
|
||||
window.plugins.jPushPlugin.stopLogPageView("onePage");
|
||||
|
||||
|
||||
## 日志等级设置
|
||||
|
||||
### API - setDebugModeFromIos
|
||||
|
||||
用于开启 Debug 模式,显示更多的日志信息。
|
||||
|
||||
建议调试时开启这个选项,不调试的时候注释这句代码,这个函数 setLogOFF 是相反的一对。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.setDebugModeFromIos()
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.setDebugModeFromIos();
|
||||
|
||||
### API - setLogOFF
|
||||
|
||||
用来关闭日志信息(除了必要的错误信息)。
|
||||
|
||||
不需要任何调试信息的时候,调用此 API(发布时建议调用此 API,用来屏蔽日志信息,节省性能消耗)。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.setLogOFF()
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.setLogOFF();
|
||||
|
||||
### API - setCrashLogON
|
||||
|
||||
用于统计用户应用崩溃日志。
|
||||
|
||||
如果需要统计 Log 信息,调用该接口。当你需要自己收集错误信息时,切记不要调用该接口。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.setCrashLogON()
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.setCrashLogON();
|
||||
|
||||
## 地理位置上报
|
||||
|
||||
### API - setLocation
|
||||
|
||||
用于统计用户地理信息。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.setLocation(latitude, longitude)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- latitude: 地理位置纬度,数值类型或纯数字的字符型均可。
|
||||
- longitude: 地理位置精度,数值类型或纯数字的字符型均可。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.setLocation(39.26,115.25);
|
||||
|
||||
## 设备平台判断
|
||||
|
||||
### API - isPlatformIOS
|
||||
|
||||
用于区分 iOS, Android 平台,以便不同设置。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.isPlatformIOS()
|
||||
|
||||
#### 代码示例
|
||||
|
||||
if(window.plugins.jPushPlugin.isPlatformIOS()) {
|
||||
// iOS
|
||||
} else {
|
||||
// Android
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
### iOS手动安装
|
||||
### iOS 手动安装
|
||||
|
||||
下载 JPush PhoneGap 插件,并解压缩,标记插件目录为:`$JPUSH_PLUGIN_DIR`
|
||||
- 下载 JPush PhoneGap 插件,并解压缩,标记插件目录为:`$JPUSH_PLUGIN_DIR`
|
||||
|
||||
- 用 xcode 打开 iOS 工程 将 `$JPUSH_PLUGIN_DIR`/src/ios/Plugins/ 拖到 project 中
|
||||
|
||||
1. 用 xcode 打开 iOS 工程 将 `$JPUSH_PLUGIN_DIR`/src/ios/Plugins/ 拖到 project 中
|
||||
2. 将 `$JPUSH_PLUGIN_DIR`/src/ios/lib/ 拖到 project 中
|
||||
- 将 `$JPUSH_PLUGIN_DIR`/src/ios/lib/ 拖到 project 中
|
||||
|
||||
4. 添加以下框架,打开 xcode,点击 project,选择(Target -> Build Phases -> Link Binary With Libraries)
|
||||
- 添加以下框架,打开 xcode,点击 project,选择(Target -> Build Phases -> Link Binary With Libraries)
|
||||
|
||||
CFNetwork.framework
|
||||
CoreFoundation.framework
|
||||
@@ -17,16 +17,16 @@
|
||||
UIKit.framework
|
||||
|
||||
|
||||
5. 在你的工程中创建一个新的 Property List 文件
|
||||
- 在你的工程中创建一个新的 Property List 文件
|
||||
|
||||
并将其命名为 PushConfig.plist,填入 Portal 为你的应用提供的 APP_KEY 等参数
|
||||
|
||||
10. 在 AppDelegate.m 中包含头文件
|
||||
- 在 AppDelegate.m 中包含头文件
|
||||
|
||||
#import "APService.h"
|
||||
#import "JPushPlugin.h"
|
||||
#import "JPUSHService.h"
|
||||
#import "JPushPlugin.h"
|
||||
|
||||
6. 调用代码,监听系统事件,相应地调用 JPush SDK 提供的 API 来实现功能
|
||||
- 在 AppDelegate.m 中的下列方法中添加代码,如果方法不存在则增加相应方法与内容
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
|
||||
//原内容保持不变
|
||||
@@ -37,17 +37,16 @@
|
||||
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
||||
//原内容保持不变
|
||||
// Required add
|
||||
[APService registerDeviceToken:deviceToken];
|
||||
[JPUSHService registerDeviceToken:deviceToken];
|
||||
}
|
||||
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
|
||||
//原内容保持不变
|
||||
// Required
|
||||
[APService handleRemoteNotification:userInfo];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification
|
||||
object:userInfo];
|
||||
// Required add
|
||||
[JPUSHService handleRemoteNotification:userInfo];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification object:userInfo];
|
||||
}
|
||||
|
||||
7. 修改 phonegap config.xml 文件用来包含 Plugin/ 内的插件
|
||||
- 修改 phonegap config.xml 文件用来包含 Plugin/ 内的插件
|
||||
|
||||
|
||||
<feature name="JPushPlugin">
|
||||
@@ -56,7 +55,8 @@
|
||||
</feature>
|
||||
|
||||
|
||||
8. 复制 `$JPUSH_PLUGIN_DIR`/www/PushNotification.js 到工程的 www 目录下面
|
||||
9. 在需要使用插件处加入
|
||||
- 复制 `$JPUSH_PLUGIN_DIR`/www/JPushPlugin.js 到工程的 www 目录下面
|
||||
|
||||
- 在需要使用插件处加入
|
||||
|
||||
<script type="text/javascript" src="JPushPlugin.js"></script>
|
||||
229
README.md
229
README.md
@@ -1,93 +1,91 @@
|
||||
## JPush PhoneGap/Cordova Plugin ##
|
||||
# JPush PhoneGap / Cordova Plugin
|
||||
|
||||
JPush-PhoneGap-Plugin 支持 iOS, Android 的推送插件。
|
||||
[](https://travis-ci.org/jpush/jpush-phonegap-plugin)
|
||||
[](https://gitter.im/jpush/jpush-phonegap-plugin)
|
||||
[](https://github.com/jpush/jpush-phonegap-plugin/releases)
|
||||
[](https://github.com/jpush/jpush-phonegap-plugin-plugin)
|
||||
[](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1)
|
||||
|
||||
**功能特性:**
|
||||
支持 iOS, Android 的极光推送插件。
|
||||
支持 iOS, Android 的 Cordova 推送插件。
|
||||
|
||||
### 功能特性
|
||||
+ 发送推送通知
|
||||
+ 发送推送自定义消息
|
||||
+ 设置推送标签和别名
|
||||
+ 设置角标(iOS)
|
||||
## 功能特性
|
||||
+ 发送推送通知。
|
||||
+ 发送推送自定义消息。
|
||||
+ 设置推送标签和别名。
|
||||
+ 设置角标(iOS)。
|
||||
|
||||
*如需要 IM 功能插件,请关注 [jmessage-phonegap-plugin](https://github.com/jpush/jmessage-phonegap-plugin)*
|
||||
*如需要 IM 功能插件,请关注 [jmessage-phonegap-plugin](https://github.com/jpush/jmessage-phonegap-plugin)*。
|
||||
|
||||
## 安装 ##
|
||||
###准备工作
|
||||
## 安装
|
||||
### 准备工作
|
||||
|
||||
1. cordova create 文件夹名字 包名 应用名字
|
||||
|
||||
cordova create Myproj com.myproj.jpush MyTestProj
|
||||
|
||||
2. 添加平台
|
||||
2. 添加平台:
|
||||
|
||||
cd Myproj
|
||||
cordova platform add android
|
||||
cordova platform add ios
|
||||
|
||||
ps:这里请注意iOS平台,必须先执行 `cordova platform add ios`,
|
||||
然后再执行 `cordova plugin add xxxxx` 命令,不然有一些必须要的链接库需要手动添加
|
||||
ps: 这里请注意iOS平台,必须先执行 cordova platform add ios,
|
||||
然后再执行 cordova plugin add xxxxx 命令,不然有一些必须要的链接库需要手动添加。
|
||||
|
||||
|
||||
###Cordova CLI / PhoneGap 安装 Android & iOS
|
||||
### 安装插件(Android & iOS)
|
||||
|
||||
1). 安装 JPush PhoneGap Plugin, 有两种方法:
|
||||
#### 1.安装 JPush PhoneGap Plugin
|
||||
安装 JPush PhoneGap Plugin 有两种方法:
|
||||
|
||||
方法一:在线安装
|
||||
|
||||
通过 cordova plugins 安装,要求 phonegap/cordova CLI 5.0+ (current stable v2.1.1)
|
||||
通过 cordova plugins 安装,要求 phonegap/cordova CLI 5.0+:
|
||||
|
||||
cordova plugin add jpush-phonegap-plugin --variable API_KEY=your_jpush_appkey
|
||||
|
||||
直接通过 url 安装(unstable)
|
||||
直接通过 url 安装:
|
||||
|
||||
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
|
||||
|
||||
[Android 手动安装文档地址](API/Android_handle_install.md)
|
||||
|
||||
2). 安装 org.apache.cordova.device
|
||||
[IOS 手动安装文档地址](API/iOS_install.md)
|
||||
|
||||
|
||||
#### 2.安装 org.apache.cordova.device 插件
|
||||
|
||||
cordova plugin add org.apache.cordova.device
|
||||
|
||||
|
||||
3). 在 js 中调用函数,初始化 JPush SDK
|
||||
#### 3.在 js 中调用函数,初始化 JPush
|
||||
|
||||
//由于 PhoneGap 插件采用了 Lazy load 的特性,所以建议在 js 文件能执行的最开始就添加
|
||||
window.plugins.jPushPlugin.init();
|
||||
|
||||
|
||||
### Android 手动安装
|
||||
|
||||
[Android 手动安装文档地址](document/Android_handle_install.md)
|
||||
## Demo
|
||||
插件中包含示例 Demo。若想参考,可以在 $JPUSH_PLUGIN_DIR/example 文件夹内找到并拷贝以下文件:
|
||||
|
||||
src/example/index.html -> www/index.html
|
||||
src/example/css/* -> www/css
|
||||
src/example/js/* -> www/js
|
||||
|
||||
### iOS 手动安装
|
||||
## 关于 PhoneGap build 云服务
|
||||
|
||||
[IOS手动安装文档地址](document/iOS_handle_install.md)
|
||||
该项目基于 cordova 实现,目前无法使用 PhoneGap build 云服务进行打包,建议使用本地环境进行打包。
|
||||
|
||||
## API 说明
|
||||
|
||||
###示例
|
||||
|
||||
"$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'云服务
|
||||
|
||||
该项目基于 cordova 实现,目前无法使用 'PhoneGap build' 云服务进行打包,建议使用本地环境进行打包
|
||||
|
||||
### API 说明
|
||||
|
||||
插件的 API 集中在 JPushPlugin.js 文件中,该文件的具体位置如下:
|
||||
插件的 API 集中在 JPushPlugin.js 文件中,该文件的具体位置如下:
|
||||
|
||||
Android:
|
||||
|
||||
@@ -97,143 +95,44 @@ iOS:
|
||||
|
||||
[Project]/www/plugins/cn.jpush.phonegap.JPushPlugin/www
|
||||
|
||||
具体的 API 请参考下面:
|
||||
### 具体的 API 请参考:
|
||||
|
||||
#### iOS 和 Android 通用 API 简介
|
||||
- [公共 API](https://github.com/jpush/jpush-phonegap-plugin/blob/dev/API/Common_detail_api.md)
|
||||
|
||||
+ 停止与恢复推送服务
|
||||
- [iOS API](https://github.com/jpush/jpush-phonegap-plugin/blob/dev/API/iOS%20API.md)
|
||||
|
||||
window.plugins.jPushPlugin.init()
|
||||
window.plugins.jPushPlugin.stopPush()
|
||||
window.plugins.jPushPlugin.resumePush()
|
||||
window.plugins.jPushPlugin.isPushStopped(callback)
|
||||
|
||||
+ 获取 RegistrationID
|
||||
|
||||
window.plugins.jPushPlugin.getRegistrationID(callback)
|
||||
|
||||
+ 别名与标签
|
||||
|
||||
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
|
||||
|
||||
+ 获取自定义消息推送内容
|
||||
|
||||
event - jpush.receiveMessage
|
||||
- [Android API](https://github.com/jpush/jpush-phonegap-plugin/blob/dev/API/Android_detail_api.md)
|
||||
|
||||
|
||||
[通用 API 详细说明](document/Common_detail_api.md)
|
||||
## 常见问题
|
||||
|
||||
#### iOS API简介
|
||||
若要使用 CLI 来编译项目,注意使用 cordova compile 而不是 cordova build,因为 cordova build 会清除对插件文件的修改。
|
||||
具体 cordova CLI 用法可参考[cordova CLI 官方文档](https://cordova.apache.org/docs/en/latest/reference/cordova-cli/index.html)。
|
||||
|
||||
+ 获取自定义消息推送内容
|
||||
### 1. Android
|
||||
|
||||
//推荐使用事件的方式传递,但同时保留了 receiveMessageIniOSCallback 的回调函数,兼容以前的代码
|
||||
window.plugins.jPushPlugin.receiveMessageIniOSCallback(data)
|
||||
eclipse 中 import PhoneGap 工程之后出现:`Type CallbackContext cannot be resolved to a type`。
|
||||
|
||||
event - jpush.receiveMessage
|
||||
解决方案:eclipse 中右键单击工程名,Build Path -> Config Build Path -> Projects -> 选中工程名称 -> CordovaLib -> 点击 add。
|
||||
|
||||
+ 页面的统计
|
||||
### 2. iOS
|
||||
|
||||
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.setLogOFF()
|
||||
window.plugins.JPushPlugin.setCrashLogON()
|
||||
|
||||
+ 地理位置上报
|
||||
|
||||
window.plugins.JPushPlugin.setLocation(latitude, longitude)
|
||||
|
||||
[iOS API 详细说明](document/iOS_detail_api.md)
|
||||
|
||||
|
||||
#### Android API简介
|
||||
|
||||
+ 获取集成日志
|
||||
|
||||
window.plugins.jPushPlugin.setDebugMode(mode)
|
||||
|
||||
+ 接收推送消息和点击通知
|
||||
|
||||
//下面这两个 API 是兼容旧有的代码
|
||||
window.plugins.jPushPlugin.receiveMessageInAndroidCallback(data)
|
||||
window.plugins.jPushPlugin.openNotificationInAndroidCallback(data)
|
||||
|
||||
+ 统计分析
|
||||
|
||||
window.plugins.jPushPlugin.setStatisticsOpen(boolean)
|
||||
|
||||
或在 MainActivity 中的 onPause() 和 onResume() 方法中分别调用
|
||||
JPushInterface.onPause(this) 和 JPushInterface.onResume(this) 来启用统计分析功能,
|
||||
如果使用这种方式启用统计分析功能,则 window.plugins.jPushPlugin.setStatisticsOpen(boolean)
|
||||
方法不再有效,建议不要同时使用。
|
||||
|
||||
+ 清除通知
|
||||
|
||||
window.plugins.jPushPlugin.clearAllNotification()
|
||||
|
||||
+ 通知栏样式定制
|
||||
|
||||
window.plugins.jPushPlugin.setBasicPushNotificationBuilder = function()
|
||||
window.plugins.jPushPlugin.setCustomPushNotificationBuilder = function()
|
||||
|
||||
+ 设置保留最近通知条数
|
||||
|
||||
window.plugins.jPushPlugin.setLatestNotificationNum(num)
|
||||
|
||||
+ 本地通知
|
||||
|
||||
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)
|
||||
|
||||
###常见问题
|
||||
|
||||
####1. Android
|
||||
|
||||
eclipse 中 PhoneGap 工程 import 之后出现:`Type CallbackContext cannot be resolved to a type`
|
||||
解决方案:eclipse 中右键单击工程名,Build Path -> Config Build Path -> Projects -> 选中工程名称 -> CordovaLib -> 点击 add
|
||||
|
||||
####2. iOS 设置 / 修改 APP_KEY
|
||||
- 设置 / 修改 APP_KEY:
|
||||
|
||||
在 PushConfig.plist 中修改。
|
||||
PushConfig.plist 其他值说明:
|
||||
CHANNEL: 渠道标识
|
||||
IsProduction: 是否生产环境(暂未启用)
|
||||
PushConfig.plist 中其他值说明:
|
||||
|
||||
- CHANNEL: 渠道标识。
|
||||
- IsProduction: 是否生产环境(暂未启用)。
|
||||
|
||||
|
||||
###更多
|
||||
- 收不到推送:
|
||||
|
||||
请首先按照正确方式再次配置证书、描述文件
|
||||
[iOS 证书设置指南](http://docs.jpush.io/client/ios_tutorials/#ios_1)。
|
||||
|
||||
|
||||
## 更多
|
||||
[JPush 官网文档](http://docs.jpush.io/)
|
||||
|
||||
如有问题可访问[极光社区](http://community.jpush.cn/)
|
||||
|
||||
@@ -1,220 +0,0 @@
|
||||
## 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,如果集成失败,可方便定位问题所在。
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setDebugMode(mode)
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- mode的值
|
||||
|
||||
- true 显示集成日志
|
||||
- false 不显示集成日志
|
||||
|
||||
|
||||
### 接收消息和点击通知事件
|
||||
#### API - receiveMessageInAndroidCallback
|
||||
|
||||
用于 Android 收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用。
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.receiveMessageInAndroidCallback = function(data)
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- data 接收到的 js 字符串,包含的 key:value 请进入该函数体查看。
|
||||
|
||||
##### 代码示例
|
||||
|
||||
#### API - openNotificationInAndroidCallback
|
||||
|
||||
当点击 Android 手机的通知栏进入应用程序时,会调用这个函数,这个函数不需要主动调用,是作为回调函数来用的。
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.openNotificationInAndroidCallback = function(data)
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- data js字符串
|
||||
|
||||
##### 代码示例
|
||||
|
||||
### 统计分析 API
|
||||
|
||||
#### API - onResume / onPause
|
||||
|
||||
这是一个 Android Local API,不是 js 的 API,请注意
|
||||
本 API 用于“用户使用时长”,“活跃用户”,“用户打开次数”的统计,并上报到服务器,在 Portal 上展示给开发者。
|
||||
|
||||
|
||||
####接口定义
|
||||
|
||||
public static void onResume(final Activity activity)
|
||||
public static void onPause(final Activity activity)
|
||||
|
||||
####参数说明
|
||||
|
||||
+ Activity 当前所在的 Activity。
|
||||
|
||||
####调用说明
|
||||
|
||||
应在所有的 Activity 的 onResume / onPause 方法里调用。
|
||||
|
||||
####代码示例
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
JPushInterface.onResume(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
JPushInterface.onPause(this);
|
||||
}
|
||||
|
||||
#### API - setStatisticsOpen(boolean)
|
||||
|
||||
用于在 js 中控制是否打开应用的统计分析功能,但如果已经添加了上面的 onResume / onPause 方法,
|
||||
就不能再通过这个方法来控制统计分析功能了。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setStatisticsOpen(boolean)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- boolean
|
||||
- true : 打开统计分析功能
|
||||
- false: 关闭统计分析功能
|
||||
|
||||
#### API - reportNotificationOpened
|
||||
|
||||
用于上报用户的通知栏被打开,或者用于上报用户自定义消息被展示等客户端需要统计的事件。
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.reportNotificationOpened(msgID)
|
||||
|
||||
##### 参数说明
|
||||
- msgID
|
||||
- 收到的通知或者自定义消息的 id
|
||||
|
||||
|
||||
### 清除通知 API
|
||||
|
||||
#### API - clearAllNotification
|
||||
|
||||
推送通知到客户端时,由 JPush SDK 展现通知到通知栏上。
|
||||
|
||||
此 API 提供清除通知的功能,包括:清除所有 JPush 展现的通知(不包括非 JPush SDK 展现的)。
|
||||
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.clearAllNotification = function()
|
||||
|
||||
### 设置允许推送时间 API
|
||||
### 设置通知静默时间 API
|
||||
### 通知栏样式定制 API
|
||||
|
||||
#### API - setBasicPushNotificationBuilder, setCustomPushNotificationBuilder
|
||||
|
||||
当用户需要定制默认的通知栏样式时,则可调用此方法。
|
||||
极光 Push SDK 提供了 2 个用于定制通知栏样式的构建类:
|
||||
|
||||
- setBasicPushNotificationBuilder
|
||||
- Basic 用于定制 Android Notification 里的 defaults / flags / icon 等基础样式(行为)。
|
||||
- setCustomPushNotificationBuilder
|
||||
- 继承 Basic 进一步让开发者定制 Notification Layout。
|
||||
|
||||
如果不调用此方法定制,则极光 Push SDK 默认的通知栏样式是:Android 标准的通知栏提示。
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setBasicPushNotificationBuilder = function()
|
||||
window.plugins.jPushPlugin.setCustomPushNotificationBuilder = function()
|
||||
|
||||
|
||||
### 设置保留最近通知条数 API
|
||||
|
||||
#### API - setLatestNotificationNum
|
||||
|
||||
通过极光推送,推送了很多通知到客户端时,如果用户不去处理,就会有很多保留在那里。
|
||||
|
||||
新版本 SDK (v1.3.0) 增加此功能,限制保留的通知条数。默认为保留最近 5 条通知。
|
||||
|
||||
开发者可通过调用此 API 来定义为不同的数量。
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setLatestNotificationNum(num)
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- num 保存的条数
|
||||
|
||||
|
||||
### 本地通知 API
|
||||
#### API - addLocalNotification,removeLocalNotification,clearLocalNotifications
|
||||
|
||||
|
||||
本地通知 API 不依赖于网络,无网条件下依旧可以触发。
|
||||
|
||||
本地通知与网络推送的通知是相互独立的,不受保留最近通知条数上限的限制。
|
||||
|
||||
本地通知的定时时间是自发送时算起的,不受中间关机等操作的影响。
|
||||
|
||||
|
||||
三个接口的功能分别为:添加一个本地通知,删除一个本地通知,删除所有的本地通知。
|
||||
|
||||
#####接口定义
|
||||
|
||||
window.plugins.jPushPlugin.addLocalNotification = function(builderId,
|
||||
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 字符串。
|
||||
@@ -1,374 +0,0 @@
|
||||
#通用 API 说明
|
||||
|
||||
|
||||
## 停止与恢复推送服务 API
|
||||
### API - init
|
||||
|
||||
调用此 API,用来开启
|
||||
JPush SDK 提供的推送服务。
|
||||
|
||||
开发者 App 可以通过调用停止推送服务 API 来停止极光推送服务。当又需要使用极光推送服务时,则必须要调用恢复推送服务 API。
|
||||
|
||||
```
|
||||
本功能是一个完全本地的状态操作。也就是说:停止推送服务的状态不会保存到服务器上。
|
||||
|
||||
如果停止推送服务后,开发者 App 被重新安装,或者被清除数据,
|
||||
|
||||
JPush SDK 会恢复正常的默认行为。(因为保存在本地的状态数据被清除掉了)。
|
||||
本功能其行为类似于网络中断的效果,即:推送服务停止期间推送的消息,
|
||||
|
||||
恢复推送服务后,如果推送的消息还在保留的时长范围内,则客户端是会收到离线消息。
|
||||
```
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.init()
|
||||
|
||||
### API - stopPush
|
||||
+ 在 Android 平台
|
||||
|
||||
+ 开发者 App 可以通过调用停止推送服务 API 来停止极光推送服务,当又需要使用极光推送服务时,则必须要调用恢复推送服务 API。
|
||||
|
||||
|
||||
+ 调用了本 API 后,JPush 推送服务完全被停止。具体表现为:
|
||||
|
||||
+ JPush Service 不在后台运行
|
||||
+ 收不到推送消息
|
||||
+ 不能通过 JPushInterface.init 恢复,需要调用 resumePush 恢复
|
||||
+ 极光推送所有的其他 API 调用都无效
|
||||
|
||||
+ iOS 平台
|
||||
|
||||
+ 不推荐调用,因为这个 API 只是让你的 DeviceToken 失效,在 设置-通知 中您的应用程序没有任何变化
|
||||
+ 推荐:设置一个 UI 界面, 提醒用户在 设置-通知 中关闭推送服务
|
||||
|
||||
### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.stopPush()
|
||||
|
||||
|
||||
#### API - resumePush
|
||||
|
||||
|
||||
恢复推送服务。调用了此 API 后
|
||||
|
||||
+ 在 Android 平台
|
||||
|
||||
+ 极光推送完全恢复正常工作,
|
||||
|
||||
+ iOS平台
|
||||
|
||||
+ 重新去APNS注册
|
||||
|
||||
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.resumePush()
|
||||
|
||||
#### API - isPushStopped
|
||||
|
||||
+ 在 Android 平台
|
||||
|
||||
+ 用来检查 Push Service 是否已经被停止
|
||||
|
||||
+ iOS平台
|
||||
|
||||
+ 平台检查推送服务是否注册
|
||||
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.isPushStopped(callback)
|
||||
|
||||
|
||||
##### 参数说明
|
||||
|
||||
+ callback 回调函数,用来通知 JPush 的推送服务是否开启
|
||||
|
||||
####代码示例
|
||||
window.plugins.jPushPlugin.resumePush(callback)
|
||||
var onCallback = function(data) {
|
||||
if(data > 0){
|
||||
// 开启
|
||||
} else {
|
||||
// 关闭
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
##获取 RegistrationID API
|
||||
|
||||
### API - getRegistrationID
|
||||
|
||||
RegistrationID 定义
|
||||
|
||||
集成了 JPush SDK 的应用程序在第一次成功注册到 JPush 服务器时,JPush 服务器会给客户端返回一个唯一的该设备的标识 - RegistrationID。
|
||||
JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
|
||||
|
||||
应用程序可以把此 RegistrationID 保存以自己的应用服务器上,然后就可以根据 RegistrationID 来向设备推送消息或者通知。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
JPushPlugin.prototype.getRegistrationID = function(callback)
|
||||
|
||||
##### 参数说明
|
||||
无
|
||||
#### 返回值
|
||||
|
||||
调用此 API 来取得应用程序对应的 RegistrationID。 只有当应用程序成功注册到 JPush 的服务器时才返回对应的值,否则返回空字符串。
|
||||
|
||||
#### 调用示例
|
||||
|
||||
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
|
||||
var onGetRegistradionID = function(data) {
|
||||
try {
|
||||
console.log("JPushPlugin:registrationID is " + data)
|
||||
} catch(exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
|
||||
##别名与标签 API
|
||||
|
||||
### API - setTagsWithAlias, setTags, setAlias
|
||||
|
||||
提供几个相关 API 用来设置别名(alias)与标签(tags)。
|
||||
|
||||
这几个 API 可以在 App 里任何地方调用。
|
||||
|
||||
**别名 Alias**
|
||||
|
||||
为安装了应用程序的用户,取个别名来标识。以后给该用户 Push 消息时,就可以用此别名来指定。
|
||||
|
||||
每个用户只能指定一个别名。
|
||||
|
||||
同一个应用程序内,对不同的用户,建议取不同的别名。这样,尽可能根据别名来唯一确定用户。
|
||||
|
||||
系统不限定一个别名只能指定一个用户。如果一个别名被指定到了多个用户,当给指定这个别名发消息时,服务器端 API 会同时给这多个用户发送消息。
|
||||
|
||||
举例:在一个用户要登录的游戏中,可能设置别名为 userid。游戏运营时,发现该用户 3 天没有玩游戏了,则根据 userid 调用服务器端 API 发通知到客户端提醒用户。
|
||||
|
||||
**标签 Tag**
|
||||
|
||||
为安装了应用程序的用户,打上标签。其目的主要是方便开发者根据标签,来批量下发 Push 消息。
|
||||
|
||||
可为每个用户打多个标签。
|
||||
|
||||
不同应用程序、不同的用户,可以打同样的标签。
|
||||
|
||||
举例: game, old_page, women
|
||||
|
||||
#### 接口定义
|
||||
|
||||
JPushPlugin.prototype.setTagsWithAlias = function(tags, alias)
|
||||
JPushPlugin.prototype.setTags = function(tags)
|
||||
JPushPlugin.prototype.setAlias = function(alias)
|
||||
|
||||
#### 参数说明
|
||||
* tags
|
||||
* 参数类型为数组
|
||||
* nil 此次调用不设置此值
|
||||
* 空集合表示取消之前的设置
|
||||
* 每次调用至少设置一个 tag,覆盖之前的设置,不是新增
|
||||
* 有效的标签组成:字母(区分大小写)、数字、下划线、汉字
|
||||
* 限制:每个 tag 命名长度限制为 40 字节,最多支持设置 100 个 tag,但总长度不得超过1K字节。(判断长度需采用UTF-8编码)
|
||||
* 单个设备最多支持设置 100 个 tag,App 全局 tag 数量无限制。
|
||||
* alias
|
||||
* 参数类型为字符串
|
||||
* nil 此次调用不设置此值
|
||||
* 空字符串 ("")表示取消之前的设置
|
||||
* 有效的别名组成:字母(区分大小写)、数字、下划线、汉字。
|
||||
* 限制:alias 命名长度限制为 40 字节。(判断长度需采用 UTF-8 编码)
|
||||
|
||||
#### 返回值说明
|
||||
|
||||
函数本身无返回值,但需要注册 `jpush.setTagsWithAlias` 事件来监听设置结果
|
||||
|
||||
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
|
||||
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) {
|
||||
console.log(exception)
|
||||
}
|
||||
}
|
||||
|
||||
####错误码定义
|
||||
|
||||
|
||||
|
||||
|
||||
|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次 |短时间内操作过于频繁|
|
||||
|
||||
|
||||
### 获取点击通知内容
|
||||
|
||||
#### 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.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":"今天去哪儿"
|
||||
},
|
||||
"key1":"value1",
|
||||
"key2":"value2",
|
||||
"_j_msgid":154604475
|
||||
}
|
||||
|
||||
### 获取通知内容
|
||||
|
||||
#### event - jpush.receiveNotification
|
||||
|
||||
点击通知进入应用程序时会触发该事件
|
||||
|
||||
#####代码示例
|
||||
|
||||
- 在你需要接收通知的的 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);
|
||||
|
||||
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":"今天去哪儿"
|
||||
},
|
||||
"key1":"value1",
|
||||
"key2":"value2",
|
||||
"_j_msgid":154604475
|
||||
}
|
||||
|
||||
|
||||
### 获取自定义消息推送内容
|
||||
|
||||
|
||||
####event - jpush.receiveMessage
|
||||
|
||||
收到应用内消息时触发这个事件
|
||||
|
||||
`推荐使用事件的方式传递,但同时保留了 receiveMessageIniOSCallback 的回调函数,兼容以前的代码`
|
||||
|
||||
|
||||
#####代码示例
|
||||
|
||||
- 在你需要接收通知的的 js 文件中加入:
|
||||
|
||||
document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);
|
||||
|
||||
- onReceiveMessage 需要这样写:
|
||||
|
||||
|
||||
var onReceiveMessage = function(event) {
|
||||
try{
|
||||
var message
|
||||
if(device.platform == "Android") {
|
||||
message = window.plugins.jPushPlugin.receiveMessage.message;
|
||||
} else {
|
||||
message = event.content;
|
||||
}
|
||||
$("#messageResult").html(message);
|
||||
|
||||
}
|
||||
catch(exception) {
|
||||
console.log("JPushPlugin:onReceiveMessage-->" + exception);
|
||||
}
|
||||
}
|
||||
|
||||
ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.receiveMessage,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意
|
||||
|
||||
+ Android
|
||||
|
||||
{"message":"今天去哪儿",
|
||||
"extras"{
|
||||
"cn.jpush.android.MSG_ID":"154378013",
|
||||
"cn.jpush.android.CONTENT_TYPE":"",
|
||||
"cn.jpush.android.EXTRA":{"key":"不添没有"}
|
||||
}
|
||||
}
|
||||
+ iOS
|
||||
|
||||
{
|
||||
"content":"今天去哪儿",
|
||||
"extras":
|
||||
{
|
||||
"key":"不填写没有"
|
||||
}
|
||||
}
|
||||
@@ -1,238 +0,0 @@
|
||||
## iOS API简介
|
||||
|
||||
### 获取 APNs(通知) 推送内容
|
||||
|
||||
|
||||
#### API - receiveMessageIniOSCallback
|
||||
|
||||
用于 iOS 收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
|
||||
不推荐使用回调函数
|
||||
|
||||
##### 接口定义
|
||||
|
||||
JPushPlugin.prototype.receiveMessageIniOSCallback = function(data)
|
||||
|
||||
#####参数说明
|
||||
|
||||
- data 是一个 js 字符串使用如下代码解析,js 具体 key 根据应用内消息来确定
|
||||
|
||||
var bToObj = JSON.parse(data)
|
||||
|
||||
#####返回值
|
||||
无
|
||||
|
||||
##### 代码示例
|
||||
|
||||
|
||||
### 页面的统计
|
||||
#### 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)
|
||||
#####参数说明
|
||||
pageName 需要统计页面自定义名称
|
||||
|
||||
duration 自定义的页面时间
|
||||
#####调用说明
|
||||
应在所有的需要统计得页面得 viewWillAppear 和 viewWillDisappear 加入 startLogPageView 和 stopLogPageView 来统计当前页面的停留时间。
|
||||
|
||||
或者直接使用 beginLogPageView 来自定义加入页面和时间信息。
|
||||
#####返回值说明
|
||||
无
|
||||
#####代码示例
|
||||
|
||||
window.plugins.jPushPlugin.beginLogPageView("newPage", 5);
|
||||
window.plugins.jPushPlugin.startLogPageView("onePage");
|
||||
window.plugins.jPushPlugin.stopLogPageView("onePage");
|
||||
|
||||
### 设置Badge
|
||||
#### API - setBadge, resetBadge
|
||||
|
||||
JPush 封装 badge 功能,允许应用上传 badge 值至 JPush 服务器,由 JPush 后台帮助管理每个用户所对应的推送 badge 值,简化了设置推送 badge 的操作。
|
||||
(本接口不会直接改变应用本地的角标值. 要修改本地 badege 值,使用 setApplicationIconBadgeNumber)
|
||||
|
||||
实际应用中,开发者可以直接对 badge 值做增减操作,无需自己维护用户与 badge 值之间的对应关系。
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.setBadge(value)
|
||||
window.plugins.jPushPlugin.prototype.reSetBadge()
|
||||
|
||||
`resetBadge相当于setBadge(0)`
|
||||
##### 参数说明
|
||||
value 取值范围:[0,99999]
|
||||
##### 返回值
|
||||
无,控制台会有 log 打印设置结果
|
||||
#####代码示例
|
||||
|
||||
window.plugins.jPushPlugin.setBadge(5);
|
||||
window.plugins.jPushPlugin.reSetBadge();
|
||||
|
||||
#### API - setApplicationIconBadgeNumber
|
||||
|
||||
本接口直接改变应用本地的角标值.
|
||||
设置 iOS 的角标,当设置 badge = 0 时为清除角标
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.setApplicationIconBadgeNumber(badge)
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- badge 整形,例如0,1,2
|
||||
- 当 badge 为 0 时,角标被清除
|
||||
|
||||
#####代码示例
|
||||
|
||||
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
|
||||
|
||||
|
||||
#### API - getApplicationIconBadgeNumber
|
||||
|
||||
获取 iOS 的角标值
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.getApplicationIconBadgeNumber(callback)
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- callback 回调函数
|
||||
|
||||
#####代码示例
|
||||
```
|
||||
|
||||
window.plugins.jPushPlugin.getApplicationIconBadgeNumber(function(data){
|
||||
console.log(data);
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
### 本地通知
|
||||
#### API - addLocalNotificationForIOS
|
||||
|
||||
API 用于注册本地通知
|
||||
|
||||
最多支持64个
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.addLocalNotificationForIOS(delayTime, content, badge, notificationID, extras)
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- delayTime 本地推送延迟多长时间后显示,数值类型或纯数字的字符型均可
|
||||
- content 本地推送需要显示的内容
|
||||
- badge 角标的数字。如果不需要改变角标传-1。数值类型或纯数字的字符型均可
|
||||
- notificationID 本地推送标识符,字符串。
|
||||
- extras 自定义参数,可以用来标识推送和增加附加信息。字典类型。
|
||||
|
||||
#####代码示例
|
||||
|
||||
window.plugins.jPushPlugin.addLocalNotificationForIOS(6*60*60, "本地推送内容", 1, "notiId", {"key":"value"});
|
||||
|
||||
#### API - deleteLocalNotificationWithIdentifierKeyInIOS
|
||||
|
||||
API 删除本地推送定义
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.deleteLocalNotificationWithIdentifierKeyInIOS(identifierKey)
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- identifierKey 本地推送标识符
|
||||
|
||||
#####代码示例
|
||||
|
||||
window.plugins.jPushPlugin.deleteLocalNotificationWithIdentifierKeyInIOS("identifier");
|
||||
|
||||
#### API - clearAllLocalNotifications
|
||||
|
||||
API 清除所有本地推送对象
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.clearAllLocalNotifications()
|
||||
|
||||
#####代码示例
|
||||
|
||||
window.plugins.jPushPlugin.clearAllLocalNotifications();
|
||||
|
||||
### 日志等级设置
|
||||
#### API - setDebugModeFromIos
|
||||
API 用于开启 Debug 模式,显示更多的日志信息
|
||||
|
||||
建议调试时开启这个选项,不调试的时候注释这句代码,这个函数 setLogOFF 是相反的一对
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.setDebugModeFromIos()
|
||||
|
||||
#####代码示例
|
||||
|
||||
window.plugins.jPushPlugin.setDebugModeFromIos();
|
||||
|
||||
#### API - setLogOFF
|
||||
|
||||
API 用来关闭日志信息(除了必要的错误信息)
|
||||
|
||||
不需要任何调试信息的时候,调用此 API(发布时建议调用此 API,用来屏蔽日志信息,节省性能消耗)
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.setLogOFF()
|
||||
|
||||
#####代码示例
|
||||
|
||||
window.plugins.jPushPlugin.setLogOFF();
|
||||
|
||||
#### API - setCrashLogON
|
||||
|
||||
API 用于统计用户应用崩溃日志
|
||||
|
||||
如果需要统计 Log 信息,调用该接口。当你需要自己收集错误信息时,切记不要调用该接口。
|
||||
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.setCrashLogON()
|
||||
|
||||
#####代码示例
|
||||
|
||||
window.plugins.jPushPlugin.setCrashLogON();
|
||||
|
||||
### 地理位置上报
|
||||
#### API - setLocation
|
||||
API 用于统计用户地理信息
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.setLocation(latitude,longitude)
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- latitude 地理位置纬度,数值类型或纯数字的字符型均可
|
||||
- longitude 地理位置精度,数值类型或纯数字的字符型均可
|
||||
|
||||
#####代码示例
|
||||
|
||||
window.plugins.jPushPlugin.setLocation(39.26,115.25);
|
||||
|
||||
### 设备平台判断
|
||||
#### API - isPlatformIOS
|
||||
API 用于区分 iOS, Android 平台,以便不同设置
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.isPlatformIOS()
|
||||
|
||||
#####代码示例
|
||||
|
||||
if(window.plugins.jPushPlugin.isPlatformIOS()){
|
||||
// iOS
|
||||
}else{
|
||||
// Android
|
||||
}
|
||||
BIN
example/.DS_Store
vendored
BIN
example/.DS_Store
vendored
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jpush-phonegap-plugin",
|
||||
"version": "2.1.1",
|
||||
"version": "2.1.6",
|
||||
"description": "JPush for cordova plugin",
|
||||
"cordova": {
|
||||
"id": "cn.jpush.phonegap.JPushPlugin",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
id="cn.jpush.phonegap.JPushPlugin"
|
||||
version="2.1.0">
|
||||
version="2.1.6">
|
||||
|
||||
<name>JPush Plugin</name>
|
||||
<description>JPush for cordova plugin</description>
|
||||
@@ -93,12 +93,14 @@
|
||||
<category android:name="$PACKAGE_NAME"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- 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"
|
||||
@@ -109,9 +111,9 @@
|
||||
<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核心功能-->
|
||||
<receiver
|
||||
android:name="cn.jpush.android.service.PushReceiver"
|
||||
|
||||
@@ -7,9 +7,10 @@ module.exports = function (context) {
|
||||
projectRoot = context.opts.projectRoot,
|
||||
ConfigParser = context.requireCordovaModule('cordova-lib/src/configparser/ConfigParser'),
|
||||
config = new ConfigParser(path.join(context.opts.projectRoot, "config.xml")),
|
||||
packageName = config.android_packageName() || config.packageName();
|
||||
packageName = config.android_packageName() || config.packageName();
|
||||
|
||||
console.info("Running android-install.Hook: " + context.hook + ", Package: " + packageName + ", Path: " + projectRoot + ".");
|
||||
console.info("Running android-install.Hook: " + context.hook
|
||||
+ ", Package: " + packageName + ", Path: " + projectRoot + ".");
|
||||
|
||||
if (!packageName) {
|
||||
console.error("Package name could not be found!");
|
||||
@@ -36,13 +37,13 @@ module.exports = function (context) {
|
||||
shell.mkdir('-p', targetDir);
|
||||
|
||||
// sync the content
|
||||
fs.readFile(path.join(context.opts.plugin.dir, 'src', 'android', 'JPushPlugin.java'), {encoding: 'utf-8'}, function (err, data) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
data = data.replace(/^import __PACKAGE_NAME__.R;/m, 'import ' + packageName + '.R;');
|
||||
fs.writeFileSync(targetFile, data);
|
||||
fs.readFile(path.join(context.opts.plugin.dir, 'src', 'android', 'JPushPlugin.java'),
|
||||
{encoding: 'utf-8'}, function (err, data) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
data = data.replace(/^import __PACKAGE_NAME__.R;/m, 'import ' + packageName + '.R;');
|
||||
fs.writeFileSync(targetFile, data);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package cn.jpush.phonegap;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Notification;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import __PACKAGE_NAME__.R;
|
||||
@@ -21,6 +19,7 @@ import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
@@ -37,31 +36,31 @@ import cn.jpush.android.data.JPushLocalNotification;
|
||||
public class JPushPlugin extends CordovaPlugin {
|
||||
private final static List<String> methodList =
|
||||
Arrays.asList(
|
||||
"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"
|
||||
"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);
|
||||
@@ -89,20 +88,20 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
super.initialize(cordova, webView);
|
||||
|
||||
Log.i(TAG, "---------------- initialize" + "-" + openNotificationAlert
|
||||
+ "-" + notificationAlert);
|
||||
+ "-" + notificationAlert);
|
||||
|
||||
cordovaActivity = this.cordova.getActivity();
|
||||
cordovaActivity = cordova.getActivity();
|
||||
|
||||
//如果同时缓存了打开事件 openNotificationAlert 和 消息事件 notificationAlert,只向 UI 发打开事件。
|
||||
//这样做是为了和 iOS 统一。
|
||||
if (openNotificationAlert != null) {
|
||||
notificationAlert = null;
|
||||
transmitNotificationOpen(openNotificationTitle, openNotificationAlert,
|
||||
openNotificationExtras);
|
||||
openNotificationExtras);
|
||||
}
|
||||
if (notificationAlert != null) {
|
||||
transmitNotificationReceive(notificationTitle, notificationAlert,
|
||||
notificationExtras);
|
||||
notificationExtras);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,28 +109,35 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
Log.i(TAG, "---------------- onPause");
|
||||
shouldCacheMsg = true;
|
||||
if (isStatisticsOpened && multitasking) {
|
||||
JPushInterface.onPause(cordovaActivity);
|
||||
JPushInterface.onPause(this.cordova.getActivity());
|
||||
}
|
||||
}
|
||||
|
||||
public void onResume(boolean multitasking) {
|
||||
shouldCacheMsg = false;
|
||||
Log.i(TAG, "---------------- onResume" + "-" + openNotificationAlert
|
||||
+ "-" + notificationAlert);
|
||||
+ "-" + notificationAlert);
|
||||
if (isStatisticsOpened && multitasking) {
|
||||
JPushInterface.onResume(cordovaActivity);
|
||||
JPushInterface.onResume(this.cordova.getActivity());
|
||||
}
|
||||
if (openNotificationAlert != null) {
|
||||
notificationAlert = null;
|
||||
transmitNotificationOpen(openNotificationTitle, openNotificationAlert,
|
||||
openNotificationExtras);
|
||||
openNotificationExtras);
|
||||
}
|
||||
if (notificationAlert != null) {
|
||||
transmitNotificationReceive(notificationTitle, notificationAlert,
|
||||
notificationExtras);
|
||||
notificationExtras);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
cordovaActivity = null;
|
||||
instance = null;
|
||||
}
|
||||
|
||||
private static JSONObject getMessageObject(String message,
|
||||
Map<String, Object> extras) {
|
||||
JSONObject data = new JSONObject();
|
||||
@@ -140,12 +146,17 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
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));
|
||||
JSONObject jo = null;
|
||||
if (TextUtils.isEmpty((String) entry.getValue())) {
|
||||
jo = new JSONObject();
|
||||
} else {
|
||||
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 {
|
||||
@@ -170,12 +181,17 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
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));
|
||||
JSONObject jo = null;
|
||||
if (TextUtils.isEmpty((String) entry.getValue())) {
|
||||
jo = new JSONObject();
|
||||
} else {
|
||||
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 {
|
||||
@@ -264,7 +280,7 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
}
|
||||
|
||||
void init(JSONArray data, CallbackContext callbackContext) {
|
||||
JPushInterface.init(cordovaActivity.getApplicationContext());
|
||||
JPushInterface.init(this.cordova.getActivity().getApplicationContext());
|
||||
}
|
||||
|
||||
void setDebugMode(JSONArray data, CallbackContext callbackContext) {
|
||||
@@ -279,18 +295,18 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
}
|
||||
|
||||
void stopPush(JSONArray data, CallbackContext callbackContext) {
|
||||
JPushInterface.stopPush(cordovaActivity.getApplicationContext());
|
||||
JPushInterface.stopPush(this.cordova.getActivity().getApplicationContext());
|
||||
callbackContext.success();
|
||||
}
|
||||
|
||||
void resumePush(JSONArray data, CallbackContext callbackContext) {
|
||||
JPushInterface.resumePush(cordovaActivity.getApplicationContext());
|
||||
JPushInterface.resumePush(this.cordova.getActivity().getApplicationContext());
|
||||
callbackContext.success();
|
||||
}
|
||||
|
||||
void isPushStopped(JSONArray data, CallbackContext callbackContext) {
|
||||
boolean isStopped = JPushInterface.isPushStopped(
|
||||
cordovaActivity.getApplicationContext());
|
||||
this.cordova.getActivity().getApplicationContext());
|
||||
if (isStopped) {
|
||||
callbackContext.success(1);
|
||||
} else {
|
||||
@@ -308,7 +324,7 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
}
|
||||
if (num != -1) {
|
||||
JPushInterface.setLatestNotificationNumber(
|
||||
cordovaActivity.getApplicationContext(), num);
|
||||
this.cordova.getActivity().getApplicationContext(), num);
|
||||
} else {
|
||||
callbackContext.error("error num");
|
||||
}
|
||||
@@ -334,30 +350,30 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
} catch (JSONException e) {
|
||||
callbackContext.error("error reading hour json");
|
||||
}
|
||||
Context context = cordovaActivity.getApplicationContext();
|
||||
Context context = this.cordova.getActivity().getApplicationContext();
|
||||
JPushInterface.setPushTime(context, days, startHour, endHour);
|
||||
callbackContext.success();
|
||||
}
|
||||
|
||||
void getRegistrationID(JSONArray data, CallbackContext callbackContext) {
|
||||
Context context = cordovaActivity.getApplicationContext();
|
||||
Context context = this.cordova.getActivity().getApplicationContext();
|
||||
String regID = JPushInterface.getRegistrationID(context);
|
||||
callbackContext.success(regID);
|
||||
}
|
||||
|
||||
void onResume(JSONArray data, CallbackContext callbackContext) {
|
||||
JPushInterface.onResume(cordovaActivity);
|
||||
JPushInterface.onResume(this.cordova.getActivity());
|
||||
}
|
||||
|
||||
void onPause(JSONArray data, CallbackContext callbackContext) {
|
||||
JPushInterface.onPause(cordovaActivity);
|
||||
JPushInterface.onPause(this.cordova.getActivity());
|
||||
}
|
||||
|
||||
void reportNotificationOpened(JSONArray data, CallbackContext callbackContext) {
|
||||
try {
|
||||
String msgID;
|
||||
msgID = data.getString(0);
|
||||
JPushInterface.reportNotificationOpened(cordovaActivity, msgID);
|
||||
JPushInterface.reportNotificationOpened(this.cordova.getActivity(), msgID);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -369,8 +385,8 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
for (int i = 0; i < data.length(); i++) {
|
||||
tags.add(data.getString(i));
|
||||
}
|
||||
JPushInterface.setTags(cordovaActivity.getApplicationContext(),
|
||||
tags, mTagWithAliasCallback);
|
||||
JPushInterface.setTags(this.cordova.getActivity().getApplicationContext(),
|
||||
tags, mTagWithAliasCallback);
|
||||
callbackContext.success();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
@@ -381,8 +397,8 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
void setAlias(JSONArray data, CallbackContext callbackContext) {
|
||||
try {
|
||||
String alias = data.getString(0);
|
||||
JPushInterface.setAlias(cordovaActivity.getApplicationContext(),
|
||||
alias, mTagWithAliasCallback);
|
||||
JPushInterface.setAlias(this.cordova.getActivity().getApplicationContext(),
|
||||
alias, mTagWithAliasCallback);
|
||||
callbackContext.success();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
@@ -399,8 +415,8 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
for (int i = 0; i < tagsArray.length(); i++) {
|
||||
tags.add(tagsArray.getString(i));
|
||||
}
|
||||
JPushInterface.setAliasAndTags(cordovaActivity.getApplicationContext(),
|
||||
alias, tags, mTagWithAliasCallback);
|
||||
JPushInterface.setAliasAndTags(this.cordova.getActivity().getApplicationContext(),
|
||||
alias, tags, mTagWithAliasCallback);
|
||||
callbackContext.success();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
@@ -411,7 +427,7 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
void setBasicPushNotificationBuilder(JSONArray data,
|
||||
CallbackContext callbackContext) {
|
||||
BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(
|
||||
cordovaActivity);
|
||||
this.cordova.getActivity());
|
||||
builder.developerArg0 = "Basic builder 1";
|
||||
JPushInterface.setPushNotificationBuilder(1, builder);
|
||||
JSONObject obj = new JSONObject();
|
||||
@@ -425,10 +441,9 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
void setCustomPushNotificationBuilder(JSONArray data,
|
||||
CallbackContext callbackContext) {
|
||||
CustomPushNotificationBuilder builder = new CustomPushNotificationBuilder(
|
||||
cordovaActivity, R.layout.test_notification_layout,
|
||||
this.cordova.getActivity(), R.layout.test_notification_layout,
|
||||
R.id.icon, R.id.title, R.id.text);
|
||||
builder.developerArg0 = "Custom Builder 1";
|
||||
builder.layoutIconDrawable = R.drawable.jpush_notification_icon;
|
||||
JPushInterface.setPushNotificationBuilder(2, builder);
|
||||
JSONObject obj = new JSONObject();
|
||||
try {
|
||||
@@ -439,7 +454,7 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
}
|
||||
|
||||
void clearAllNotification(JSONArray data, CallbackContext callbackContext) {
|
||||
JPushInterface.clearAllNotifications(cordovaActivity);
|
||||
JPushInterface.clearAllNotifications(this.cordova.getActivity());
|
||||
}
|
||||
|
||||
void clearNotificationById(JSONArray data, CallbackContext callbackContext) {
|
||||
@@ -451,7 +466,7 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
callbackContext.error("error reading id json");
|
||||
}
|
||||
if (notificationId != -1) {
|
||||
JPushInterface.clearNotificationById(cordovaActivity, notificationId);
|
||||
JPushInterface.clearNotificationById(this.cordova.getActivity(), notificationId);
|
||||
} else {
|
||||
callbackContext.error("error id");
|
||||
}
|
||||
@@ -467,7 +482,7 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
String extrasStr = data.isNull(5) ? "" : data.getString(5);
|
||||
JSONObject extras = new JSONObject();
|
||||
if (!extrasStr.isEmpty()) {
|
||||
extras = new JSONObject(extrasStr);
|
||||
extras = new JSONObject(extrasStr);
|
||||
}
|
||||
|
||||
JPushLocalNotification ln = new JPushLocalNotification();
|
||||
@@ -478,17 +493,17 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
ln.setBroadcastTime(System.currentTimeMillis() + broadcastTime);
|
||||
ln.setExtras(extras.toString());
|
||||
|
||||
JPushInterface.addLocalNotification(cordovaActivity, ln);
|
||||
JPushInterface.addLocalNotification(this.cordova.getActivity(), ln);
|
||||
}
|
||||
|
||||
void removeLocalNotification(JSONArray data, CallbackContext callbackContext)
|
||||
throws JSONException {
|
||||
int notificationID = data.getInt(0);
|
||||
JPushInterface.removeLocalNotification(cordovaActivity, notificationID);
|
||||
JPushInterface.removeLocalNotification(this.cordova.getActivity(), notificationID);
|
||||
}
|
||||
|
||||
void clearLocalNotifications(JSONArray data, CallbackContext callbackContext) {
|
||||
JPushInterface.clearLocalNotifications(cordovaActivity);
|
||||
JPushInterface.clearLocalNotifications(this.cordova.getActivity());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -502,47 +517,47 @@ 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.");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 设置通知静默时间
|
||||
* 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(this.cordova.getActivity(), 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 isValidHour(int hour) {
|
||||
return !(hour < 0 || hour > 23);
|
||||
}
|
||||
|
||||
private boolean isValidMinute(int minute) {
|
||||
return !(minute < 0 || minute > 59);
|
||||
}
|
||||
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);
|
||||
}
|
||||
/**
|
||||
* 用于 Android 6.0 以上系统申请权限,具体可参考:
|
||||
* http://docs.Push.io/client/android_api/#android-60
|
||||
*/
|
||||
void requestPermission(JSONArray data, CallbackContext callbackContext) {
|
||||
JPushInterface.requestPermission(this.cordova.getActivity());
|
||||
}
|
||||
|
||||
private final TagAliasCallback mTagWithAliasCallback = new TagAliasCallback() {
|
||||
@Override
|
||||
@@ -558,7 +573,7 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
final String jsEvent = String.format(
|
||||
"cordova.fireDocumentEvent('jpush.setTagsWithAlias',%s)",
|
||||
data.toString());
|
||||
cordovaActivity.runOnUiThread(new Runnable() {
|
||||
cordova.getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
instance.webView.loadUrl("javascript:" + jsEvent);
|
||||
|
||||
@@ -9,20 +9,29 @@
|
||||
#import "AppDelegate+JPush.h"
|
||||
#import "JPushPlugin.h"
|
||||
#import "JPUSHService.h"
|
||||
#import <objc/runtime.h>
|
||||
|
||||
@implementation AppDelegate (JPush)
|
||||
|
||||
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
|
||||
[JPushPlugin setLaunchOptions:launchOptions];
|
||||
+(void)load{
|
||||
|
||||
//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;
|
||||
Method origin;
|
||||
Method swizzle;
|
||||
|
||||
origin=class_getInstanceMethod([self class],@selector(init));
|
||||
swizzle=class_getInstanceMethod([self class], @selector(init_plus));
|
||||
method_exchangeImplementations(origin, swizzle);
|
||||
}
|
||||
|
||||
-(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];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
||||
|
||||
@@ -60,10 +60,11 @@
|
||||
|
||||
/*
|
||||
* 以下为js中可监听到的事件
|
||||
* jpush.openNotification 点击推送消息唤醒或启动app
|
||||
* jpush.openNotification 点击推送消息启动或唤醒app
|
||||
* jpush.setTagsWithAlias 设置标签、别名完成
|
||||
* jpush.receiveMessage 收到自定义消息
|
||||
* jpush.receiveNotification 前台收到推送消息
|
||||
* jpush.receiveNotification 前台收到推送
|
||||
* jpush.backgoundNotification 后台收到推送
|
||||
*/
|
||||
|
||||
@end
|
||||
|
||||
@@ -356,29 +356,33 @@ static NSDictionary *_luanchOptions = nil;
|
||||
|
||||
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
|
||||
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
|
||||
NSLog(@"%ld",(long)[UIApplication sharedApplication].applicationState);
|
||||
switch ([UIApplication sharedApplication].applicationState) {
|
||||
case UIApplicationStateActive:
|
||||
{
|
||||
case UIApplicationStateActive:{
|
||||
//前台收到
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveNotification',%@)",jsonString]];
|
||||
});
|
||||
}
|
||||
break;
|
||||
case UIApplicationStateInactive:
|
||||
case UIApplicationStateBackground:
|
||||
{
|
||||
}
|
||||
case UIApplicationStateInactive:{
|
||||
//后台点击
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]];
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
case UIApplicationStateBackground:{
|
||||
//后台收到
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.backgoundNotification',%@)",jsonString]];
|
||||
});
|
||||
break;
|
||||
}
|
||||
default:
|
||||
//do nothing
|
||||
break;
|
||||
//do nothing
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -340,8 +340,16 @@ JPushPlugin.prototype.requestPermission = function() {
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setSilenceTime = function() {
|
||||
|
||||
JPushPlugin.prototype.setSilenceTime = function(startHour, startMinute, endHour, endMinute) {
|
||||
if (device.platform == "Android") {
|
||||
this.call_native("setSilenceTime", [startHour, startMinute, endHour, endMinute], null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setPushTime = function(weekdays, startHour, endHour) {
|
||||
if (device.platform == "Android") {
|
||||
this.call_native("setPushTime", [weekdays, startHour, endHour], null);
|
||||
}
|
||||
}
|
||||
|
||||
if(!window.plugins) {
|
||||
|
||||
Reference in New Issue
Block a user