Skip to content

Commit 2a05ea1

Browse files
author
Hevin
committed
Merge branch 'master' into dev
2 parents b3b2af1 + 9d3d32d commit 2a05ea1

File tree

3 files changed

+33
-26
lines changed

3 files changed

+33
-26
lines changed

doc/Common_detail_api.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,11 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
161161

162162
#### 接口定义
163163

164-
JPushPlugin.prototype.setTagsWithAlias(tags, alias)
165-
JPushPlugin.prototype.setTags(tags)
166-
JPushPlugin.prototype.setAlias(alias)
164+
```js
165+
JPushPlugin.prototype.setTagsWithAlias(tags, alias, successCallback, errorCallback)
166+
JPushPlugin.prototype.setTags(tags, successCallback, errorCallback)
167+
JPushPlugin.prototype.setAlias(alias, successCallback, errorCallback)
168+
```
167169

168170
#### 参数说明
169171
* tags:
@@ -181,17 +183,15 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
181183
* 有效的别名组成:字母(区分大小写)、数字、下划线、汉字。
182184
* 限制:alias 命名长度限制为 40 字节(判断长度需采用 UTF-8 编码)。
183185

184-
#### 返回值说明
185-
186-
函数本身无返回值,但需要注册 `jpush.setTagsWithAlias` 事件来监听设置结果:
186+
#### 代码示例
187187

188-
document.addEventListener("jpush.setTagsWithAlias", function(event) {
189-
console.log("onTagsWithAlias")
190-
var result = "result code:" + event.resultCode + " "
191-
result += "tags:" + event.tags + " "
192-
result += "alias:" + event.alias + " "
193-
$("#tagAliasResult").html(result)
194-
}, false)
188+
```js
189+
window.plugins.jPushPlugin.setTagsWithAlias([tag1, tag2], alias1, function () {
190+
// success callback.
191+
}, function (errorMsg) {
192+
// errorMsg 格式为 'errorCode: error message'.
193+
})
194+
```
195195

196196
#### 错误码定义
197197

example/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@
116116
if (tag3 != "") {
117117
tags.push(tag3);
118118
}
119-
window.plugins.jPushPlugin.setTagsWithAlias(tags, alias);
119+
window.plugins.jPushPlugin.setTagsWithAlias(tags, alias, function () {
120+
// Success callback
121+
console.log(tags + ' - ' + alias)
122+
});
120123
} catch (exception) {
121124
console.log(exception);
122125
}

www/JPushPlugin.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ JPushPlugin.prototype.errorCallback = function (msg) {
1717
console.log('JPush Callback Error: ' + msg)
1818
}
1919

20-
JPushPlugin.prototype.callNative = function (name, args, successCallback) {
21-
cordova.exec(successCallback, this.errorCallback, 'JPushPlugin', name, args)
20+
JPushPlugin.prototype.callNative = function (name, args, successCallback, errorCallback) {
21+
if (errorCallback) {
22+
cordova.exec(successCallback, errorCallback, 'JPushPlugin', name, args)
23+
} else {
24+
cordova.exec(successCallback, this.errorCallback, 'JPushPlugin', name, args)
25+
}
2226
}
2327

2428
// Common methods
@@ -66,7 +70,7 @@ JPushPlugin.prototype.clearLocalNotifications = function () {
6670
}
6771
}
6872

69-
JPushPlugin.prototype.setTagsWithAlias = function (tags, alias) {
73+
JPushPlugin.prototype.setTagsWithAlias = function (tags, alias, successCallback, errorCallback) {
7074
if (tags == null) {
7175
this.setAlias(alias)
7276
return
@@ -77,15 +81,15 @@ JPushPlugin.prototype.setTagsWithAlias = function (tags, alias) {
7781
}
7882
var arrayTagWithAlias = [tags]
7983
arrayTagWithAlias.unshift(alias)
80-
this.callNative('setTagsWithAlias', arrayTagWithAlias, null)
84+
this.callNative('setTagsWithAlias', arrayTagWithAlias, successCallback, errorCallback)
8185
}
8286

83-
JPushPlugin.prototype.setTags = function (tags) {
84-
this.callNative('setTags', tags, null)
87+
JPushPlugin.prototype.setTags = function (tags, successCallback, errorCallback) {
88+
this.callNative('setTags', tags, successCallback, errorCallback)
8589
}
8690

87-
JPushPlugin.prototype.setAlias = function (alias) {
88-
this.callNative('setAlias', [alias], null)
91+
JPushPlugin.prototype.setAlias = function (alias, successCallback, errorCallback) {
92+
this.callNative('setAlias', [alias], successCallback, errorCallback)
8993
}
9094

9195
// 判断系统设置中是否对本应用启用通知。
@@ -205,13 +209,13 @@ JPushPlugin.prototype.addNotificationActions = function (actions, categoryId) {
205209

206210
// Android methods
207211
JPushPlugin.prototype.setBasicPushNotificationBuilder = function () {
208-
if (device.platform == 'Android') {
212+
if (device.platform === 'Android') {
209213
this.callNative('setBasicPushNotificationBuilder', [], null)
210214
}
211215
}
212216

213217
JPushPlugin.prototype.setCustomPushNotificationBuilder = function () {
214-
if (device.platform == 'Android') {
218+
if (device.platform === 'Android') {
215219
this.callNative('setCustomPushNotificationBuilder', [], null)
216220
}
217221
}
@@ -258,14 +262,14 @@ JPushPlugin.prototype.clearNotificationById = function (id) {
258262
}
259263

260264
JPushPlugin.prototype.setLatestNotificationNum = function (num) {
261-
if (device.platform == 'Android') {
265+
if (device.platform === 'Android') {
262266
this.callNative('setLatestNotificationNum', [num], null)
263267
}
264268
}
265269

266270
JPushPlugin.prototype.addLocalNotification = function (builderId, content, title,
267271
notificationID, broadcastTime, extras) {
268-
if (device.platform == 'Android') {
272+
if (device.platform === 'Android') {
269273
this.callNative('addLocalNotification',
270274
[builderId, content, title, notificationID, broadcastTime, extras], null)
271275
}

0 commit comments

Comments
 (0)