Merge branch 'master' into dev

This commit is contained in:
Hevin 2017-05-26 16:18:08 +08:00
commit 2a05ea1784
3 changed files with 33 additions and 26 deletions

View File

@ -161,9 +161,11 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
#### 接口定义
JPushPlugin.prototype.setTagsWithAlias(tags, alias)
JPushPlugin.prototype.setTags(tags)
JPushPlugin.prototype.setAlias(alias)
```js
JPushPlugin.prototype.setTagsWithAlias(tags, alias, successCallback, errorCallback)
JPushPlugin.prototype.setTags(tags, successCallback, errorCallback)
JPushPlugin.prototype.setAlias(alias, successCallback, errorCallback)
```
#### 参数说明
* tags:
@ -181,17 +183,15 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
* 有效的别名组成:字母(区分大小写)、数字、下划线、汉字。
* 限制alias 命名长度限制为 40 字节(判断长度需采用 UTF-8 编码)。
#### 返回值说明
#### 代码示例
函数本身无返回值,但需要注册 `jpush.setTagsWithAlias` 事件来监听设置结果:
document.addEventListener("jpush.setTagsWithAlias", function(event) {
console.log("onTagsWithAlias")
var result = "result code:" + event.resultCode + " "
result += "tags:" + event.tags + " "
result += "alias:" + event.alias + " "
$("#tagAliasResult").html(result)
}, false)
```js
window.plugins.jPushPlugin.setTagsWithAlias([tag1, tag2], alias1, function () {
// success callback.
}, function (errorMsg) {
// errorMsg 格式为 'errorCode: error message'.
})
```
#### 错误码定义

View File

@ -116,7 +116,10 @@
if (tag3 != "") {
tags.push(tag3);
}
window.plugins.jPushPlugin.setTagsWithAlias(tags, alias);
window.plugins.jPushPlugin.setTagsWithAlias(tags, alias, function () {
// Success callback
console.log(tags + ' - ' + alias)
});
} catch (exception) {
console.log(exception);
}

View File

@ -17,8 +17,12 @@ JPushPlugin.prototype.errorCallback = function (msg) {
console.log('JPush Callback Error: ' + msg)
}
JPushPlugin.prototype.callNative = function (name, args, successCallback) {
JPushPlugin.prototype.callNative = function (name, args, successCallback, errorCallback) {
if (errorCallback) {
cordova.exec(successCallback, errorCallback, 'JPushPlugin', name, args)
} else {
cordova.exec(successCallback, this.errorCallback, 'JPushPlugin', name, args)
}
}
// Common methods
@ -66,7 +70,7 @@ JPushPlugin.prototype.clearLocalNotifications = function () {
}
}
JPushPlugin.prototype.setTagsWithAlias = function (tags, alias) {
JPushPlugin.prototype.setTagsWithAlias = function (tags, alias, successCallback, errorCallback) {
if (tags == null) {
this.setAlias(alias)
return
@ -77,15 +81,15 @@ JPushPlugin.prototype.setTagsWithAlias = function (tags, alias) {
}
var arrayTagWithAlias = [tags]
arrayTagWithAlias.unshift(alias)
this.callNative('setTagsWithAlias', arrayTagWithAlias, null)
this.callNative('setTagsWithAlias', arrayTagWithAlias, successCallback, errorCallback)
}
JPushPlugin.prototype.setTags = function (tags) {
this.callNative('setTags', tags, null)
JPushPlugin.prototype.setTags = function (tags, successCallback, errorCallback) {
this.callNative('setTags', tags, successCallback, errorCallback)
}
JPushPlugin.prototype.setAlias = function (alias) {
this.callNative('setAlias', [alias], null)
JPushPlugin.prototype.setAlias = function (alias, successCallback, errorCallback) {
this.callNative('setAlias', [alias], successCallback, errorCallback)
}
// 判断系统设置中是否对本应用启用通知。
@ -205,13 +209,13 @@ JPushPlugin.prototype.addNotificationActions = function (actions, categoryId) {
// Android methods
JPushPlugin.prototype.setBasicPushNotificationBuilder = function () {
if (device.platform == 'Android') {
if (device.platform === 'Android') {
this.callNative('setBasicPushNotificationBuilder', [], null)
}
}
JPushPlugin.prototype.setCustomPushNotificationBuilder = function () {
if (device.platform == 'Android') {
if (device.platform === 'Android') {
this.callNative('setCustomPushNotificationBuilder', [], null)
}
}
@ -258,14 +262,14 @@ JPushPlugin.prototype.clearNotificationById = function (id) {
}
JPushPlugin.prototype.setLatestNotificationNum = function (num) {
if (device.platform == 'Android') {
if (device.platform === 'Android') {
this.callNative('setLatestNotificationNum', [num], null)
}
}
JPushPlugin.prototype.addLocalNotification = function (builderId, content, title,
notificationID, broadcastTime, extras) {
if (device.platform == 'Android') {
if (device.platform === 'Android') {
this.callNative('addLocalNotification',
[builderId, content, title, notificationID, broadcastTime, extras], null)
}