Skip to content

Commit 8c7d187

Browse files
KenChoiKenChoi
authored andcommitted
prepare release v1.6.3
1 parent 2f022c3 commit 8c7d187

File tree

3 files changed

+173
-7
lines changed

3 files changed

+173
-7
lines changed

android/src/main/java/cn/jpush/reactnativejpush/JPushModule.java

Lines changed: 162 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,14 @@ public void resumePush() {
100100
Logger.toast(mContext, "Resume push success");
101101
}
102102

103-
//为用户设置Tag,可以在服务端根据Tag推送消息
103+
/**
104+
* Set tags, this API is covering logic not incremental logic, means call this API will cover tags which
105+
* have been set. See document https://docs.jiguang.cn/jpush/client/Android/android_api/#api_3
106+
* for detail.
107+
*
108+
* @param strArray tags array
109+
* @param callback callback
110+
*/
104111
@ReactMethod
105112
public void setTags(final ReadableArray strArray, final Callback callback) {
106113
mContext = getCurrentActivity();
@@ -117,7 +124,7 @@ public void setTags(final ReadableArray strArray, final Callback callback) {
117124
// final ProgressDialog dialog = new ProgressDialog(mContext);
118125
// dialog.setMessage("Loading");
119126
// dialog.show();
120-
JPushInterface.setAliasAndTags(getReactApplicationContext(), null,
127+
JPushInterface.setTags(getReactApplicationContext(),
121128
tagSet, new TagAliasCallback() {
122129
@Override
123130
public void gotResult(int status, String desc, Set<String> set) {
@@ -142,19 +149,49 @@ public void gotResult(int status, String desc, Set<String> set) {
142149
}
143150
});
144151
} else {
145-
Logger.toast(mContext, "Empty tag ");
152+
Logger.toast(mContext, "Empty tag, try to cancel tags ");
153+
Logger.i(TAG, "Empty tag, will cancel early settings");
154+
JPushInterface.setTags(getReactApplicationContext(), new LinkedHashSet<String>(), new TagAliasCallback() {
155+
@Override
156+
public void gotResult(int status, String desc, Set<String> set) {
157+
switch (status) {
158+
case 0:
159+
Logger.i(TAG, "Cancel tag success. ");
160+
Logger.toast(getReactApplicationContext(), "Cancel tag success");
161+
callback.invoke(0);
162+
break;
163+
case 6002:
164+
Logger.i(TAG, "Set tag timeout");
165+
Logger.toast(getReactApplicationContext(),
166+
"Set tag timeout, check your network");
167+
callback.invoke("Set tag timeout");
168+
break;
169+
default:
170+
Logger.toast(getReactApplicationContext(),
171+
"Error code: " + status);
172+
callback.invoke("Set tag failed. Error code: " + status);
173+
}
174+
}
175+
});
146176
}
147177
}
148178

149-
//为用户设置别名,可以在服务端根据别名推送
179+
/**
180+
* Set alias. This API is covering logic rather then incremental logic, means call this API will cover alias
181+
* that have been set before. See document: https://docs.jiguang.cn/jpush/client/Android/android_api/#api_3
182+
* for detail.
183+
*
184+
* @param str alias string.
185+
* @param callback callback
186+
*/
150187
@ReactMethod
151188
public void setAlias(String str, final Callback callback) {
152189
mContext = getCurrentActivity();
153190
final String alias = str.trim();
154191
Logger.i(TAG, "alias: " + alias);
155192
if (!TextUtils.isEmpty(alias)) {
156-
JPushInterface.setAliasAndTags(getReactApplicationContext(), alias,
157-
null, new TagAliasCallback() {
193+
JPushInterface.setAlias(getReactApplicationContext(), alias,
194+
new TagAliasCallback() {
158195
@Override
159196
public void gotResult(int status, String desc, Set<String> set) {
160197
switch (status) {
@@ -177,6 +214,125 @@ public void gotResult(int status, String desc, Set<String> set) {
177214
});
178215
} else {
179216
Logger.toast(mContext, "Empty alias ");
217+
Logger.i(TAG, "Empty alias, will cancel early alias setting");
218+
JPushInterface.setAlias(getReactApplicationContext(), "", new TagAliasCallback() {
219+
@Override
220+
public void gotResult(int status, String desc, Set<String> set) {
221+
switch (status) {
222+
case 0:
223+
Logger.i(TAG, "Cancel alias success");
224+
Logger.toast(getReactApplicationContext(), "Cancel alias success");
225+
callback.invoke(0);
226+
break;
227+
case 6002:
228+
Logger.i(TAG, "Set alias timeout");
229+
Logger.toast(getReactApplicationContext(),
230+
"set alias timeout, check your network");
231+
callback.invoke("Set alias timeout");
232+
break;
233+
default:
234+
Logger.toast(getReactApplicationContext(), "Error code: " + status);
235+
callback.invoke("Set alias failed. Error code: " + status);
236+
}
237+
}
238+
});
239+
}
240+
}
241+
242+
/**
243+
* Set alias and tags. This API is covering logic rather then incremental logic, means call this
244+
* API will override early settings. See document for detail:
245+
* https://docs.jiguang.cn/jpush/client/Android/android_api/#api_3
246+
*
247+
* @param alias alias string
248+
* @param tagArray tags
249+
* @param callback callback
250+
*/
251+
@ReactMethod
252+
public void setAliasAndTags(String alias, ReadableArray tagArray, final Callback callback) {
253+
if (tagArray != null) {
254+
Logger.i(TAG, "tag: " + tagArray.toString());
255+
if (tagArray.size() > 0) {
256+
Set<String> tagSet = new LinkedHashSet<>();
257+
for (int i = 0; i < tagArray.size(); i++) {
258+
if (!ExampleUtil.isValidTagAndAlias(tagArray.getString(i))) {
259+
Logger.toast(mContext, "Invalid tag !");
260+
return;
261+
}
262+
tagSet.add(tagArray.getString(i));
263+
}
264+
JPushInterface.setAliasAndTags(getReactApplicationContext(), alias, tagSet, new TagAliasCallback() {
265+
@Override
266+
public void gotResult(int status, String desc, Set<String> set) {
267+
switch (status) {
268+
case 0:
269+
Logger.i(TAG, "Set alias and tags success");
270+
Logger.toast(getReactApplicationContext(), "Set alias and tags success");
271+
callback.invoke(0);
272+
break;
273+
case 6002:
274+
Logger.i(TAG, "Set alias timeout");
275+
Logger.toast(getReactApplicationContext(),
276+
"set alias timeout, check your network");
277+
callback.invoke("Set alias timeout");
278+
break;
279+
default:
280+
Logger.toast(getReactApplicationContext(), "Error code: " + status);
281+
Logger.i(TAG, "Set alias and tags failed, error code: " + status);
282+
callback.invoke("Set alias and tags failed. Error code: " + status);
283+
}
284+
}
285+
});
286+
} else {
287+
Logger.i(TAG, "Calling setAliasAndTags, tags is empty, will cancel tags settings");
288+
JPushInterface.setAliasAndTags(getReactApplicationContext(), alias, new LinkedHashSet<String>(),
289+
new TagAliasCallback() {
290+
@Override
291+
public void gotResult(int status, String s, Set<String> set) {
292+
switch (status) {
293+
case 0:
294+
Logger.i(TAG, "Set alias and tags success");
295+
Logger.toast(getReactApplicationContext(), "Set alias and tags success");
296+
callback.invoke(0);
297+
break;
298+
case 6002:
299+
Logger.i(TAG, "Set alias timeout");
300+
Logger.toast(getReactApplicationContext(),
301+
"set alias timeout, check your network");
302+
callback.invoke("Set alias timeout");
303+
break;
304+
default:
305+
Logger.toast(getReactApplicationContext(), "Error code: " + status);
306+
Logger.i(TAG, "Set alias and tags failed, error code: " + status + " error message: " + s);
307+
callback.invoke("Set alias and tags failed. Error code: " + status);
308+
}
309+
}
310+
});
311+
}
312+
} else {
313+
Logger.i(TAG, "Tag array is null, will not set tag this time.");
314+
JPushInterface.setAliasAndTags(getReactApplicationContext(), alias, null, new TagAliasCallback() {
315+
@Override
316+
public void gotResult(int status, String s, Set<String> set) {
317+
switch (status) {
318+
case 0:
319+
Logger.i(TAG, "Set alias and tags success");
320+
Logger.toast(getReactApplicationContext(), "Set alias and tags success");
321+
callback.invoke(0);
322+
break;
323+
case 6002:
324+
Logger.i(TAG, "Set alias timeout");
325+
Logger.toast(getReactApplicationContext(),
326+
"set alias timeout, check your network");
327+
callback.invoke("Set alias timeout");
328+
break;
329+
default:
330+
Logger.toast(getReactApplicationContext(), "Error code: " + status);
331+
Logger.i(TAG, "Set alias and tags failed, error code: " + status + " error message: " + s);
332+
callback.invoke("Set alias and tags failed. Error code: " + status);
333+
}
334+
}
335+
});
180336
}
181337
}
182338

index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ export default class JPush {
114114
});
115115
}
116116

117+
static setAliasAndTags(alias, tag, success, fail) {
118+
JPushModule.setAliasAndTags(alias, tag, (resultCode) => {
119+
if (resultCode === 0) {
120+
success();
121+
} else {
122+
fail();
123+
}
124+
});
125+
}
126+
117127
/**
118128
* Android
119129
*/

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jpush-react-native",
3-
"version": "1.6.2",
3+
"version": "1.6.3",
44
"description": "a jpush plugin for react native application",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)