Skip to content

Commit d35f59a

Browse files
authored
Merge pull request #554 from jpush/dev
Dev
2 parents e3d753d + 6befe18 commit d35f59a

File tree

6 files changed

+108
-7
lines changed

6 files changed

+108
-7
lines changed

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

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import com.facebook.react.bridge.Arguments;
1414
import com.facebook.react.bridge.Callback;
15+
import com.facebook.react.bridge.LifecycleEventListener;
1516
import com.facebook.react.bridge.ReactApplicationContext;
1617
import com.facebook.react.bridge.ReactContextBaseJavaModule;
1718
import com.facebook.react.bridge.ReactMethod;
@@ -39,7 +40,7 @@
3940
import cn.jpush.android.data.JPushLocalNotification;
4041
import cn.jpush.android.service.JPushMessageReceiver;
4142

42-
public class JPushModule extends ReactContextBaseJavaModule {
43+
public class JPushModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
4344

4445
private static String TAG = "JPushModule";
4546
private Context mContext;
@@ -62,6 +63,7 @@ public class JPushModule extends ReactContextBaseJavaModule {
6263

6364
public JPushModule(ReactApplicationContext reactContext) {
6465
super(reactContext);
66+
reactContext.addLifecycleEventListener(this);
6567
}
6668

6769
@Override
@@ -83,6 +85,7 @@ public void initialize() {
8385
@Override
8486
public void onCatalystInstanceDestroy() {
8587
super.onCatalystInstanceDestroy();
88+
Logger.i(TAG, "onCatalystInstanceDestroy");
8689
mCachedBundle = null;
8790
mRidBundle = null;
8891
mConnectCachedBundle = null;
@@ -93,6 +96,7 @@ public void onCatalystInstanceDestroy() {
9396
mRidEvent = null;
9497
mConnectEvent = null;
9598
mGetRidCallback = null;
99+
mRAC = null;
96100
}
97101

98102
@ReactMethod
@@ -511,6 +515,41 @@ public void sendLocalNotification(ReadableMap map) {
511515
}
512516
}
513517

518+
@ReactMethod
519+
public void removeLocalNotification(int id) {
520+
try {
521+
Logger.d(TAG, "removeLocalNotification:"+id);
522+
JPushInterface.removeLocalNotification(getReactApplicationContext(), id);
523+
} catch (Exception e) {
524+
e.printStackTrace();
525+
}
526+
}
527+
@ReactMethod
528+
public void clearLocalNotifications() {
529+
try {
530+
Logger.d(TAG, "clearLocalNotifications");
531+
JPushInterface.clearLocalNotifications(getReactApplicationContext());
532+
} catch (Exception e) {
533+
e.printStackTrace();
534+
}
535+
}
536+
537+
@Override
538+
public void onHostResume() {
539+
Logger.d(TAG, "onHostResume");
540+
}
541+
542+
@Override
543+
public void onHostPause() {
544+
Logger.d(TAG, "onHostPause");
545+
}
546+
547+
@Override
548+
public void onHostDestroy() {
549+
Logger.d(TAG, "onHostDestroy");
550+
mRAC = null;
551+
}
552+
514553
/**
515554
* 接收自定义消息,通知,通知点击事件等事件的广播
516555
* 文档链接:http://docs.jiguang.cn/client/android_api/

documents/api.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
* [setTags](#settags)
1212
* [cleanTags](#cleantags)
1313
* [sendLocalNotification](#sendlocalnotification)
14+
* [clearLocalNotifications](#clearlocalnotifications)
15+
* [removeLocalNotification](#removelocalnotification)
1416
* [clearAllNotifications](#clearallnotifications)
1517
* [clearNotificationById](#clearnotificationbyId)
1618
* [点击推送事件](#点击推送事件)
@@ -194,6 +196,23 @@ JPushModule.resumePush();
194196
})
195197
```
196198

199+
#### clearLocalNotifications
200+
201+
移除所有的本地通知
202+
203+
```
204+
JPushModule.clearLocalNotifications();
205+
```
206+
207+
#### removeLocalNotification
208+
209+
根据 notificationId 移除指定的本地通知, notificationId 为 int 类型。
210+
211+
```
212+
var notificationId = 5;
213+
JPushModule.removeLocalNotification(notificationId);
214+
```
215+
197216
#### clearAllNotifications
198217

199218
清除所有通知
@@ -208,7 +227,7 @@ JPushModule.clearAllNotifications();
208227

209228
```
210229
var notificationId = 5;
211-
JPushModule.clearNotificationById(id);
230+
JPushModule.clearNotificationById(notificationId);
212231
```
213232

214233
#### 点击推送事件

documents/api_en.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* [Receive Notification event](#receive-notification-event)
1414
* [Receive Custom Message Event](#receive-custom-message-event)
1515
* [sendLocalNotification](#sendlocalnotification)
16+
* [removeLocalNotification](#removelocalnotification)
17+
* [clearLocalNotifications](#clearlocalnotifications)
1618
* [clearAllNotifications](#clearallnotifications)
1719
* [clearNotificationById](#clearnotificationbyId)
1820
* [iOS Only API](#ios-only-api)
@@ -149,6 +151,23 @@ reset tags.
149151
})
150152
```
151153

154+
#### clearLocalNotifications
155+
156+
Removes all local notifications
157+
158+
```
159+
JPushModule.clearLocalNotifications();
160+
```
161+
162+
#### removeLocalNotification
163+
164+
Remove the specified local notification by notificationId(int type)。
165+
166+
```
167+
var notificationId = 5;
168+
JPushModule.removeLocalNotification(id);
169+
```
170+
152171
#### clearAllNotifications
153172

154173
Clear all notifications.

index.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,15 @@ export default class JPush {
9999
}
100100

101101
/**
102-
* Android Only
102+
* Android Only.
103+
* 删除通知栏指定的推送。
103104
*/
104105
static clearNotificationById (id) {
105-
JPushModule.clearNotificationById(id)
106+
if (Platform.OS == "android") {
107+
JPushModule.clearNotificationById(id)
108+
} else {
109+
console.warn("iOS 没有提供该方法!")
110+
}
106111
}
107112

108113
/**
@@ -627,6 +632,20 @@ export default class JPush {
627632
JPushModule.sendLocalNotification(notification)
628633
}
629634

635+
/**
636+
* 移除所有的本地通知
637+
*/
638+
static clearLocalNotifications() {
639+
JPushModule.clearLocalNotifications()
640+
}
641+
642+
/**
643+
* 移除指定未触发的本地通知。
644+
*/
645+
static removeLocalNotification(id) {
646+
JPushModule.removeLocalNotification(id)
647+
}
648+
630649
/**
631650
* iOS Only
632651
* 设置应用 Badge(小红点)

ios/RCTJPushModule/RCTJPushModule.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,12 +870,17 @@ - (void)didRegistRemoteNotification:(NSString *)token {
870870
}
871871
}
872872

873-
RCT_EXPORT_METHOD(clearNotificationById:(NSInteger)identify) {
873+
RCT_EXPORT_METHOD(removeLocalNotification:(NSInteger)identify) {
874874
JPushNotificationIdentifier *pushIdentify = [[JPushNotificationIdentifier alloc] init];
875875
pushIdentify.identifiers = @[[@(identify) description]];
876876
[JPUSHService removeNotification: pushIdentify];
877877
}
878878

879+
RCT_EXPORT_METHOD(clearLocalNotifications) {
880+
[JPUSHService removeNotification: nil];
881+
}
882+
883+
879884
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
880885
NSDictionary * userInfo = notification.request.content.userInfo;
881886
[JPUSHService handleRemoteNotification:userInfo];

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jpush-react-native",
3-
"version": "2.2.11",
3+
"version": "2.2.12",
44
"description": "a jpush plugin for react native application",
55
"main": "index.js",
66
"scripts": {
@@ -24,7 +24,7 @@
2424
},
2525
"homepage": "https://github.com/jpush/jpush-react-native#readme",
2626
"peerDependencies": {
27-
"jcore-react-native": ">= 1.2.0"
27+
"jcore-react-native": ">= 1.2.10"
2828
},
2929
"devDependencies": {
3030
"babel-eslint": "^7.2.3",

0 commit comments

Comments
 (0)