Skip to content

Commit a084808

Browse files
Merge pull request #773 from RokieGodFather/master
新增部分新的接口
2 parents 04c3f63 + 443c564 commit a084808

File tree

5 files changed

+102
-3
lines changed

5 files changed

+102
-3
lines changed

android/src/main/java/cn/jiguang/plugins/push/JPushModule.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,41 @@ public void deleteGeofence(ReadableMap readableMap) {
461461
}
462462
}
463463

464+
@ReactMethod
465+
public void clearAllNotifications(){
466+
JPushInterface.clearAllNotifications(reactContext);
467+
}
468+
469+
@ReactMethod
470+
public void clearNotificationById(ReadableMap readableMap){
471+
if (readableMap == null){
472+
JLogger.w(JConstants.PARAMS_NULL);
473+
return;
474+
}
475+
if (readableMap.hasKey(JConstants.NOTIFICATION_ID)){
476+
Integer id = readableMap.getInt(JConstants.NOTIFICATION_ID);
477+
JPushInterface.clearNotificationById(reactContext,id);
478+
}else {
479+
JLogger.w("there are no " + JConstants.GEO_FENCE_ID);
480+
}
481+
}
482+
483+
@ReactMethod
484+
public void setPowerSaveMode(boolean bool){
485+
JPushInterface.setPowerSaveMode(reactContext,bool);
486+
}
487+
488+
@ReactMethod
489+
public void isNotificationEnabled(Callback callback){
490+
Integer isEnabled = JPushInterface.isNotificationEnabled(reactContext);
491+
if (callback == null){
492+
JLogger.w(JConstants.CALLBACK_NULL);
493+
return;
494+
}
495+
callback.invoke(isEnabled);
496+
}
497+
498+
464499
//*****************************应用前后台状态监听*****************************
465500
public static void registerActivityLifecycle(Application application) {
466501
application.registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {

android/src/main/java/cn/jiguang/plugins/push/common/JConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class JConstants {
3333
//通知消息
3434
public static final String NOTIFICATION_EVENT_TYPE = "notificationEventType";
3535
public static final String NOTIFICATION_MAX_NUMBER = "notificationMaxNumber";
36+
public static final String NOTIFICATION_ID = "notificationId";
3637
//cmd消息
3738
public static final String COMMAND = "command";
3839
public static final String COMMAND_EXTRA = "commandExtra";

index.d.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ type Alias = {
3838
alias: string;
3939
};
4040

41+
type NotificationId = {
42+
/**
43+
* 通知 ID
44+
* */
45+
notificationId: String;
46+
};
4147
export default class JPush {
4248
/**
4349
* 设置调试模式,默认关闭状态
@@ -133,6 +139,16 @@ export default class JPush {
133139
*/
134140
static initCrashHandler(): void;
135141

142+
/**
143+
* JPush SDK 开启和关闭省电模式,默认为关闭。
144+
*/
145+
static setPowerSaveMode(enable: boolean):void;
146+
147+
/**
148+
* 检查当前应用的通知开关是否开启
149+
* */
150+
static isNotificationEnabled(callback: Callback<boolean>): void;
151+
136152
//***************************************本地通知***************************************
137153

138154
/**
@@ -167,6 +183,17 @@ export default class JPush {
167183
*/
168184
static clearLocalNotifications(): void;
169185

186+
/**
187+
* 清除所有 JPush 展现的通知(不包括非 JPush SDK 展现的)
188+
*
189+
*/
190+
static clearAllNotifications():void;
191+
192+
/**
193+
* 删除指定的通知
194+
* */
195+
static clearNotificationById(params: NotificationId):void;
196+
170197
//***************************************地理围栏***************************************
171198

172199
/**

index.js

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export default class JPush {
170170
JPushModule.getAllTags(params)
171171
}
172172
}
173-
173+
174174
/*
175175
* 设置别名
176176
* 需要理解的是,这个接口是覆盖逻辑,而不是增量逻辑。即新的调用会覆盖之前的设置
@@ -252,6 +252,24 @@ export default class JPush {
252252
}
253253
}
254254

255+
/*
256+
* JPush SDK 开启和关闭省电模式,默认为关闭。
257+
* */
258+
static setPowerSaveMode(enable){
259+
if (Platform.OS == "android"){
260+
JPushModule.setPowerSaveMode(enable)
261+
}
262+
}
263+
264+
/*
265+
* 检查当前应用的通知开关是否开启
266+
* */
267+
static isNotificationEnabled(callback){
268+
if (Platform.OS == "android"){
269+
JPushModule.isNotificationEnabled(callback)
270+
}
271+
}
272+
255273
//***************************************本地通知***************************************
256274

257275
/*
@@ -304,6 +322,24 @@ export default class JPush {
304322
}
305323
}
306324

325+
/*
326+
* 清除所有 JPush 展现的通知(不包括非 JPush SDK 展现的)
327+
* */
328+
static clearAllNotifications(){
329+
if (Platform.OS == "android") {
330+
JPushModule.clearAllNotifications();
331+
}
332+
}
333+
334+
/*
335+
* 删除指定的通知
336+
* */
337+
static clearNotificationById(params){
338+
if (Platform.OS == "android") {
339+
JPushModule.clearNotificationById(params);
340+
}
341+
}
342+
307343
//***************************************地理围栏***************************************
308344

309345
/*
@@ -334,7 +370,7 @@ export default class JPush {
334370
//连接状态
335371
static addConnectEventListener(callback) {
336372
listeners[callback] = DeviceEventEmitter.addListener(
337-
ConnectEvent, result => {
373+
ConnectEvent, result => {
338374
callback(result)
339375
})
340376
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"types": "index.d.ts",
77
"license": "ISC",
88
"author": "wicked.tc130",
9-
"version": "2.7.5",
9+
"version": "2.7.6",
1010
"repository": {
1111
"type": "git",
1212
"url": "https://github.com/jpush/jpush-react-native"

0 commit comments

Comments
 (0)