iOS - update

1.增加本地通知事件
2.更新 doc
3.fix bug
This commit is contained in:
pikacode
2016-12-06 13:56:27 +08:00
parent 7ca29c3397
commit 309131e944
6 changed files with 335 additions and 164 deletions

View File

@@ -10,12 +10,14 @@
- [获取自定义消息内容](#获取自定义消息内容)
- [设置Badge](#设置badge)
- [本地通知](#本地通知)
- [获取本地通知内容](#获取本地通知内容)
- [页面的统计](#页面的统计)
- [日志等级设置](#日志等级设置)
- [地理位置上报](#地理位置上报)
- [设备平台判断](#设备平台判断)
- [iOS 10 进阶推送特性](#ios-10-进阶推送特性)
- [获取用户推送设置](#获取用户推送设置)
- [监听事件统一说明](#监听事件统一说明)
## 开始与停止推送服务
@@ -35,7 +37,9 @@ JPush SDK 会恢复正常的默认行为。(因为保存在本地的状态数
#### 接口定义
window.plugins.jPushPlugin.init()
```
window.plugins.jPushPlugin.init()
```
### API - stopPush
@@ -52,7 +56,10 @@ JPush SDK 会恢复正常的默认行为。(因为保存在本地的状态数
#### 接口定义
window.plugins.jPushPlugin.resumePush()
```
window.plugins.jPushPlugin.resumePush()
```
### API - isPushStopped
@@ -61,7 +68,9 @@ iOS平台检查推送服务是否停止。
#### 接口定义
window.plugins.jPushPlugin.isPushStopped(callback)
```
window.plugins.jPushPlugin.isPushStopped(callback)
```
#### 参数说明
@@ -69,13 +78,15 @@ iOS平台检查推送服务是否停止。
#### 代码示例
window.plugins.jPushPlugin.isPushStopped(function(data) {
if(data > 0) {
// 已关闭
} else {
// 已开启
}
})
```js
window.plugins.jPushPlugin.isPushStopped(function(data) {
if(data > 0) {
// 已关闭
} else {
// 已开启
}
})
```
## 获取 RegistrationID
@@ -90,7 +101,9 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
#### 接口定义
JPushPlugin.prototype.getRegistrationID(callback)
```js
JPushPlugin.prototype.getRegistrationID(callback)
```
#### 返回值
@@ -98,9 +111,13 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
#### 调用示例
window.plugins.jPushPlugin.getRegistrationID(function(data) {
console.log("JPushPlugin:registrationID is " + data)
})
```js
window.plugins.jPushPlugin.getRegistrationID(function(data) {
console.log("JPushPlugin:registrationID is " + data)
})
```
## 别名与标签
@@ -134,38 +151,43 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
#### 接口定义
JPushPlugin.prototype.setTagsWithAlias(tags, alias)
JPushPlugin.prototype.setTags(tags)
JPushPlugin.prototype.setAlias(alias)
```
JPushPlugin.prototype.setTagsWithAlias(tags, alias)
JPushPlugin.prototype.setTags(tags)
JPushPlugin.prototype.setAlias(alias)
```
#### 参数说明
* tags:
* 参数类型为数组。
* nil 此次调用不设置此值
* 空集合表示取消之前的设置
* 每次调用至少设置一个 tag覆盖之前的设置不是新增
* 有效的标签组成:字母(区分大小写)、数字、下划线、汉字
* 限制:每个 tag 命名长度限制为 40 字节,最多支持设置 100 个 tag但总长度不得超过1K字节判断长度需采用UTF-8编码
* 单个设备最多支持设置 100 个 tagApp 全局 tag 数量无限制
* alias:
* 参数类型为字符串。
* nil 此次调用不设置此值
* 空字符串 "")表示取消之前的设置
* 有效的别名组成:字母(区分大小写)、数字、下划线、汉字
* 限制alias 命名长度限制为 40 字节(判断长度需采用 UTF-8 编码)
- tags:
- 参数类型为数组
- nil 此次调用不设置此值
- 空集合表示取消之前的设置
- 每次调用至少设置一个 tag覆盖之前的设置不是新增
- 有效的标签组成:字母(区分大小写)、数字、下划线、汉字
- 限制:每个 tag 命名长度限制为 40 字节,最多支持设置 100 个 tag但总长度不得超过1K字节判断长度需采用UTF-8编码
- 单个设备最多支持设置 100 个 tagApp 全局 tag 数量无限制。
- alias:
- 参数类型为字符串
- nil 此次调用不设置此值
- 空字符串 "")表示取消之前的设置
- 有效的别名组成:字母(区分大小写)、数字、下划线、汉字
- 限制alias 命名长度限制为 40 字节(判断长度需采用 UTF-8 编码)。
#### 返回值说明
函数本身无返回值,但需要注册 `jpush.setTagsWithAlias` 事件来监听设置结果。
var onTagsWithAlias = function(event) {
console.log("onTagsWithAlias")
var result = "result code:"+event.resultCode + " "
result += "tags:" + event.tags + " "
result += "alias:" + event.alias + " "
$("#tagAliasResult").html(result)
}
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false)
```js
var onTagsWithAlias = function(event) {
console.log("onTagsWithAlias")
var result = "result code:"+event.resultCode + " "
result += "tags:" + event.tags + " "
result += "alias:" + event.alias + " "
$("#tagAliasResult").html(result)
}
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false)
```
#### 错误码定义
@@ -181,7 +203,6 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
| 6008 | tag/alias 超出总长度限制 | 总长度最多 1K 字节。 |
| 6011 | 10s内设置tag或alias大于3次 | 短时间内操作过于频繁。 |
## 获取 APNS 推送内容
### 点击推送通知
@@ -194,28 +215,34 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
- 在你需要接收通知的的 js 文件中加入:
document.addEventListener("jpush.openNotification", onOpenNotification, false)
```js
document.addEventListener("jpush.openNotification", onOpenNotification, false)
```
- onOpenNotification 需要这样写:
var onOpenNotification = function(event) {
var alertContent
alertContent = event.aps.alert
alert("open Notificaiton:" + alertContent)
}
```js
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
}
```json
{
"aps":{
"badge":1,
"sound":"default",
"alert":"今天去哪儿"
},
"key1":"value1",
"key2":"value2",
"_j_msgid":154604475
}
```
### 前台收到推送
@@ -227,28 +254,34 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
- 在你需要接收通知的的 js 文件中加入:
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false)
```js
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false)
```
- onReceiveNotification 需要这样写:
var onReceiveNotification = function(event) {
var alertContent
alertContent = event.aps.alert
alert("open Notificaiton:" + alertContent)
}
```js
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
}
```json
{
"aps":{
"badge":1,
"sound":"default",
"alert":"今天去哪儿"
},
"key1":"value1",
"key2":"value2",
"_j_msgid":154604475
}
```
### 后台收到推送
@@ -260,28 +293,39 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
- 在你需要接收通知的的 js 文件中加入:
document.addEventListener("jpush.backgroundNotification", onBackgroundNotification, false)
```js
document.addEventListener("jpush.backgroundNotification", onBackgroundNotification, false)
```
- onBackgroundNotification 需要这样写:
var onBackgroundNotification = function(event) {
var alertContent
alertContent = event.aps.alert
alert("open Notificaiton:" + alertContent)
}
```js
var onBackgroundNotification = function(event) {
var alertContent
alertContent = event.aps.alert
alert("open Notificaiton:" + alertContent)
}
```
- event 举例
```json
{
"aps":{
"badge":1,
"sound":"default",
"alert":"今天去哪儿"
},
"key1":"value1",
"key2":"value2",
"_j_msgid":154604475
}
```
+ event 举例
{
"aps":{
"badge":1,
"sound":"default",
"alert":"今天去哪儿"
},
"key1":"value1",
"key2":"value2",
"_j_msgid":154604475
}
## 获取自定义消息内容
@@ -293,53 +337,67 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
- 在你需要接收通知的的 js 文件中加入:
document.addEventListener("jpush.receiveMessage", onReceiveMessage, false)
```js
document.addEventListener("jpush.receiveMessage", onReceiveMessage, false)
```
- onReceiveMessage 需要这样写:
var onReceiveMessage = function(event) {
try {
var message = event.content
$("#messageResult").html(message)
} catch(exception) {
console.log("JPushPlugin:onReceiveMessage-->" + exception);
}
```js
var onReceiveMessage = function(event) {
try {
var message = event.content
$("#messageResult").html(message)
} catch(exception) {
console.log("JPushPlugin:onReceiveMessage-->" + exception);
}
}
```
- event 举例:
```json
{
"content":"今天去哪儿",
"extras":
{
"content":"今天去哪儿",
"extras":
{
"key":"不填写没有"
}
"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()
```js
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()
```js
window.plugins.jPushPlugin.setBadge(5)
window.plugins.jPushPlugin.reSetBadge()
```
### API - setApplicationIconBadgeNumber
@@ -347,7 +405,9 @@ value 取值范围:[0,99999]。
#### 接口定义
window.plugins.jPushPlugin.prototype.setApplicationIconBadgeNumber(badge)
```js
window.plugins.jPushPlugin.prototype.setApplicationIconBadgeNumber(badge)
```
#### 参数说明
@@ -355,7 +415,9 @@ value 取值范围:[0,99999]。
#### 代码示例
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0)
```
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0)
```
### API - getApplicationIconBadgeNumber
@@ -363,7 +425,9 @@ value 取值范围:[0,99999]。
#### 接口定义
window.plugins.jPushPlugin.prototype.getApplicationIconBadgeNumber(callback)
```
window.plugins.jPushPlugin.prototype.getApplicationIconBadgeNumber(callback)
```
#### 参数说明
@@ -371,10 +435,11 @@ value 取值范围:[0,99999]。
#### 代码示例
window.plugins.jPushPlugin.getApplicationIconBadgeNumber(function(data) {
console.log(data)
})
```js
window.plugins.jPushPlugin.getApplicationIconBadgeNumber(function(data) {
console.log(data)
})
```
## 本地通知
@@ -384,7 +449,9 @@ value 取值范围:[0,99999]。
#### 接口定义
window.plugins.jPushPlugin.prototype.addLocalNotificationForIOS(delayTime, content, badge, notificationID, extras)
```js
window.plugins.jPushPlugin.prototype.addLocalNotificationForIOS(delayTime, content, badge, notificationID, extras)
```
#### 参数说明
@@ -396,7 +463,9 @@ value 取值范围:[0,99999]。
#### 代码示例
window.plugins.jPushPlugin.addLocalNotificationForIOS(6*60*60, "本地推送内容", 1, "notiId", {"key":"value"});
```js
window.plugins.jPushPlugin.addLocalNotificationForIOS(24*60*60, "本地推送内容", 1, "notiId", {"key":"value"});
```
### API - deleteLocalNotificationWithIdentifierKeyInIOS
@@ -404,7 +473,9 @@ value 取值范围:[0,99999]。
#### 接口定义
window.plugins.jPushPlugin.prototype.deleteLocalNotificationWithIdentifierKeyInIOS(identifierKey)
```js
window.plugins.jPushPlugin.prototype.deleteLocalNotificationWithIdentifierKeyInIOS(identifierKey)
```
#### 参数说明
@@ -412,7 +483,9 @@ value 取值范围:[0,99999]。
#### 代码示例
window.plugins.jPushPlugin.deleteLocalNotificationWithIdentifierKeyInIOS("identifier")
```
window.plugins.jPushPlugin.deleteLocalNotificationWithIdentifierKeyInIOS("identifier")
```
### API - clearAllLocalNotifications
@@ -420,11 +493,36 @@ value 取值范围:[0,99999]。
#### 接口定义
window.plugins.jPushPlugin.prototype.clearAllLocalNotifications()
```
window.plugins.jPushPlugin.prototype.clearAllLocalNotifications()
```
#### 代码示例
window.plugins.jPushPlugin.clearAllLocalNotifications()
```
window.plugins.jPushPlugin.clearAllLocalNotifications()
```
## 获取本地通知内容
### iOS 10 before 收到本地通知
监听 `jpush.receiveLocalNotification` 事件获取「App 在后台时点击通知横幅」或「App 在前台时收到」均会触发该事件。
### iOS 10 收到本地通知
监听 [jpush.receiveNotification](#前台收到推送)、[jpush.openNotification](点击推送通知),获取推送内容后,通过获取到的 `__JPUSHNotificationKey` 字段([本地通知](#本地通知) 设置的 `notificationID`)来判断是本地通知,并处理。
### 点击本地通知横幅启动 App
监听 `jpush.startLocalNotification` 事件。
## 页面的统计
@@ -436,9 +534,11 @@ value 取值范围:[0,99999]。
#### 接口定义
window.plugins.jPushPlugin.prototype.startLogPageView(pageName)
window.plugins.jPushPlugin.prototype.stopLogPageView(pageName)
window.plugins.jPushPlugin.prototype.beginLogPageView(pageName, duration)
```
window.plugins.jPushPlugin.prototype.startLogPageView(pageName)
window.plugins.jPushPlugin.prototype.stopLogPageView(pageName)
window.plugins.jPushPlugin.prototype.beginLogPageView(pageName, duration)
```
#### 参数说明
@@ -446,16 +546,18 @@ value 取值范围:[0,99999]。
- duration: 自定义的页面时间
#### 调用说明
应在所有的需要统计得页面得 viewWillAppear 和 viewWillDisappear 加入 startLogPageView 和 stopLogPageView 来统计当前页面的停留时间。
或者直接使用 beginLogPageView 来自定义加入页面和时间信息。
#### 代码示例
window.plugins.jPushPlugin.beginLogPageView("newPage", 5);
window.plugins.jPushPlugin.startLogPageView("onePage");
window.plugins.jPushPlugin.stopLogPageView("onePage");
```
window.plugins.jPushPlugin.beginLogPageView("newPage", 5);
window.plugins.jPushPlugin.startLogPageView("onePage");
window.plugins.jPushPlugin.stopLogPageView("onePage");
```
## 日志等级设置
@@ -467,11 +569,15 @@ value 取值范围:[0,99999]。
#### 接口定义
window.plugins.jPushPlugin.prototype.setDebugModeFromIos()
```
window.plugins.jPushPlugin.prototype.setDebugModeFromIos()
```
#### 代码示例
window.plugins.jPushPlugin.setDebugModeFromIos();
```
window.plugins.jPushPlugin.setDebugModeFromIos();
```
### API - setLogOFF
@@ -481,11 +587,15 @@ value 取值范围:[0,99999]。
#### 接口定义
window.plugins.jPushPlugin.prototype.setLogOFF()
```
window.plugins.jPushPlugin.prototype.setLogOFF()
```
#### 代码示例
window.plugins.jPushPlugin.setLogOFF();
```
window.plugins.jPushPlugin.setLogOFF();
```
### API - setCrashLogON
@@ -495,11 +605,15 @@ value 取值范围:[0,99999]。
#### 接口定义
window.plugins.jPushPlugin.prototype.setCrashLogON()
```
window.plugins.jPushPlugin.prototype.setCrashLogON()
```
#### 代码示例
window.plugins.jPushPlugin.setCrashLogON();
```
window.plugins.jPushPlugin.setCrashLogON();
```
## 地理位置上报
@@ -509,7 +623,9 @@ value 取值范围:[0,99999]。
#### 接口定义
window.plugins.jPushPlugin.prototype.setLocation(latitude, longitude)
```
window.plugins.jPushPlugin.prototype.setLocation(latitude, longitude)
```
#### 参数说明
@@ -518,7 +634,9 @@ value 取值范围:[0,99999]。
#### 代码示例
window.plugins.jPushPlugin.setLocation(39.26,115.25);
```
window.plugins.jPushPlugin.setLocation(39.26,115.25);
```
## 设备平台判断
@@ -528,15 +646,19 @@ value 取值范围:[0,99999]。
#### 接口定义
window.plugins.jPushPlugin.prototype.isPlatformIOS()
```
window.plugins.jPushPlugin.prototype.isPlatformIOS()
```
#### 代码示例
if(window.plugins.jPushPlugin.isPlatformIOS()) {
// iOS
} else {
// Android
}
```js
if(window.plugins.jPushPlugin.isPlatformIOS()) {
// iOS
} else {
// Android
}
```
@@ -577,7 +699,7 @@ window.plugins.jPushPlugin.prototype.addDismissActions(actions, categoryId);
#### 代码示例
```
```js
window.plugins.jPushPlugin.addDismissActions([{"title":"t1", "identifier":"id1", "option":"0"}, {"title":"t2", "identifier":"id2", "option":"3", "type":"textInput", "textInputButtonTitle":"回复", "textInputPlaceholder":"点此输入回复内容"}], "categoryId_t1_t2");
```
@@ -649,8 +771,6 @@ window.plugins.jPushPlugin.prototype.addNotificationActions(actions, categoryId)
7. 立即发送。
## 获取用户推送设置
### API - getUserNotificationSettings
@@ -681,6 +801,58 @@ window.plugins.jPushPlugin.prototype.getUserNotificationSettings(callback)
- UNNotificationSettingDisabled = 1, The notification setting is turned off.
- UNNotificationSettingEnabled = 2, The notification setting is turned on.
- 字段 alertStyle取值如下
- UNAlertStyleNone = 0
- UNAlertStyleBanner = 1
- UNAlertStyleAlert = 2
- UNAlertStyleNone = 0
- UNAlertStyleBanner = 1
- UNAlertStyleAlert = 2
## 监听事件统一说明
可在 js 监听全部事件如下:
##### jpush.receiveNotification
> [前台收到远程通知](#前台收到推送)
>
> [iOS 10 前台收到本地通知](#ios-10-收到本地通知)
##### jpush.openNotification
> [点击远程通知横幅使 App「进入前台」或「启动」](#点击推送通知)
>
> [iOS 10 点击本地通知横幅使 App「进入前台」或「启动」](#ios-10-收到本地通知)
##### jpush.backgroundNotification
> [iOS 7 以后后台收到远程通知](#后台收到推送)
##### jpush.setTagsWithAlias
> [设置标签别名回调](#返回值说明)
##### jpush.receiveMessage
> [获取自定义消息内容](#获取自定义消息内容)
##### jpush.startLocalNotification
> [点击本地通知横幅启动 App](#点击本地通知横幅启动-app)
##### jpush.receiveLocalNotification
> [iOS 10 before 收到本地通知](#ios-10-before-收到本地通知)