From c4b08dd92856176e29fd12d4b5b76091d06da004 Mon Sep 17 00:00:00 2001 From: JoshLi <542938192@qq.com> Date: Thu, 18 Oct 2018 17:11:41 +0800 Subject: [PATCH 1/7] Fix bug --- .../jpush/reactnativejpush/JPushModule.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/cn/jpush/reactnativejpush/JPushModule.java b/android/src/main/java/cn/jpush/reactnativejpush/JPushModule.java index 3957fbaf..a658cbf8 100644 --- a/android/src/main/java/cn/jpush/reactnativejpush/JPushModule.java +++ b/android/src/main/java/cn/jpush/reactnativejpush/JPushModule.java @@ -12,6 +12,7 @@ import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.Callback; +import com.facebook.react.bridge.LifecycleEventListener; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; @@ -39,7 +40,7 @@ import cn.jpush.android.data.JPushLocalNotification; import cn.jpush.android.service.JPushMessageReceiver; -public class JPushModule extends ReactContextBaseJavaModule { +public class JPushModule extends ReactContextBaseJavaModule implements LifecycleEventListener { private static String TAG = "JPushModule"; private Context mContext; @@ -62,6 +63,7 @@ public class JPushModule extends ReactContextBaseJavaModule { public JPushModule(ReactApplicationContext reactContext) { super(reactContext); + reactContext.addLifecycleEventListener(this); } @Override @@ -83,6 +85,7 @@ public void initialize() { @Override public void onCatalystInstanceDestroy() { super.onCatalystInstanceDestroy(); + Logger.i(TAG, "onCatalystInstanceDestroy"); mCachedBundle = null; mRidBundle = null; mConnectCachedBundle = null; @@ -93,6 +96,7 @@ public void onCatalystInstanceDestroy() { mRidEvent = null; mConnectEvent = null; mGetRidCallback = null; + mRAC = null; } @ReactMethod @@ -511,6 +515,22 @@ public void sendLocalNotification(ReadableMap map) { } } + @Override + public void onHostResume() { + Logger.d(TAG, "onHostResume"); + } + + @Override + public void onHostPause() { + Logger.d(TAG, "onHostPause"); + } + + @Override + public void onHostDestroy() { + Logger.d(TAG, "onHostDestroy"); + mRAC = null; + } + /** * 接收自定义消息,通知,通知点击事件等事件的广播 * 文档链接:http://docs.jiguang.cn/client/android_api/ From eedc84b76a49dece6d4553d1f762640560422a1f Mon Sep 17 00:00:00 2001 From: JoshLi <542938192@qq.com> Date: Thu, 18 Oct 2018 17:12:53 +0800 Subject: [PATCH 2/7] Release v2.2.11 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c3fe9c4a..3f9a2b98 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jpush-react-native", - "version": "2.2.10", + "version": "2.2.11", "description": "a jpush plugin for react native application", "main": "index.js", "scripts": { @@ -24,7 +24,7 @@ }, "homepage": "https://github.com/jpush/jpush-react-native#readme", "peerDependencies": { - "jcore-react-native": ">= 1.2.0" + "jcore-react-native": ">= 1.2.10" }, "devDependencies": { "babel-eslint": "^7.2.3", From 200eb5eae86d6d84b1cbb0a3bcbd8d5e24cb3ddb Mon Sep 17 00:00:00 2001 From: JoshLi <542938192@qq.com> Date: Thu, 18 Oct 2018 20:19:23 +0800 Subject: [PATCH 3/7] Add removeLocalNotification API for Android --- .../jpush/reactnativejpush/JPushModule.java | 19 +++++++++++++++++++ documents/api.md | 19 +++++++++++++++++++ documents/api_en.md | 19 +++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/android/src/main/java/cn/jpush/reactnativejpush/JPushModule.java b/android/src/main/java/cn/jpush/reactnativejpush/JPushModule.java index a658cbf8..6be2b11e 100644 --- a/android/src/main/java/cn/jpush/reactnativejpush/JPushModule.java +++ b/android/src/main/java/cn/jpush/reactnativejpush/JPushModule.java @@ -515,6 +515,25 @@ public void sendLocalNotification(ReadableMap map) { } } + @ReactMethod + public void removeLocalNotification(int id) { + try { + Logger.d(TAG, "removeLocalNotification:"+id); + JPushInterface.removeLocalNotification(getReactApplicationContext(), id); + } catch (Exception e) { + e.printStackTrace(); + } + } + @ReactMethod + public void clearLocalNotifications() { + try { + Logger.d(TAG, "clearLocalNotifications"); + JPushInterface.clearLocalNotifications(getReactApplicationContext()); + } catch (Exception e) { + e.printStackTrace(); + } + } + @Override public void onHostResume() { Logger.d(TAG, "onHostResume"); diff --git a/documents/api.md b/documents/api.md index bafe27c3..03cb80bb 100644 --- a/documents/api.md +++ b/documents/api.md @@ -11,6 +11,8 @@ * [setTags](#settags) * [cleanTags](#cleantags) * [sendLocalNotification](#sendlocalnotification) + * [clearLocalNotifications](#clearLocalNotifications) + * [removeLocalNotification](#removeLocalNotification) * [clearAllNotifications](#clearallnotifications) * [clearNotificationById](#clearnotificationbyId) * [点击推送事件](#点击推送事件) @@ -194,6 +196,23 @@ JPushModule.resumePush(); }) ``` +#### clearLocalNotifications + +移除所有的本地通知 + +``` +JPushModule.clearLocalNotifications(); +``` + +#### removeLocalNotification + +根据 notificationId 移除指定的本地通知, notificationId 为 int 类型。 + +``` +var notificationId = 5; +JPushModule.removeLocalNotification(id); +``` + #### clearAllNotifications 清除所有通知 diff --git a/documents/api_en.md b/documents/api_en.md index fe7a0b86..c327f70c 100644 --- a/documents/api_en.md +++ b/documents/api_en.md @@ -13,6 +13,8 @@ * [Receive Notification event](#receive-notification-event) * [Receive Custom Message Event](#receive-custom-message-event) * [sendLocalNotification](#sendlocalnotification) + * [removeLocalNotification](#removeLocalNotification) + * [clearLocalNotifications](#clearLocalNotifications) * [clearAllNotifications](#clearallnotifications) * [clearNotificationById](#clearnotificationbyId) * [iOS Only API](#ios-only-api) @@ -149,6 +151,23 @@ reset tags. }) ``` +#### clearLocalNotifications + +Removes all local notifications + +``` +JPushModule.clearLocalNotifications(); +``` + +#### removeLocalNotification + +Remove the specified local notification by notificationId(int type)。 + +``` +var notificationId = 5; +JPushModule.removeLocalNotification(id); +``` + #### clearAllNotifications Clear all notifications. From ba5b111378f3e22f736eceefcb9529df8f0b1cf1 Mon Sep 17 00:00:00 2001 From: JoshLi <542938192@qq.com> Date: Thu, 18 Oct 2018 20:26:58 +0800 Subject: [PATCH 4/7] Prepare to release v2.2.12 --- index.js | 22 ++++++++++++++++++++++ package.json | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index cad80558..48e0e53c 100644 --- a/index.js +++ b/index.js @@ -627,6 +627,28 @@ export default class JPush { JPushModule.sendLocalNotification(notification) } + /** + * 移除所有的本地通知 + */ + static clearLocalNotifications() { + if (Platform.OS == "android") { + JPushModule.clearLocalNotifications() + } else { + + } + } + + /** + * 移除指定的本地通知 + */ + static removeLocalNotification(id) { + if (Platform.OS == "android") { + JPushModule.removeLocalNotification(id) + } else { + + } + } + /** * iOS Only * 设置应用 Badge(小红点) diff --git a/package.json b/package.json index 3f9a2b98..244fdf34 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jpush-react-native", - "version": "2.2.11", + "version": "2.2.12", "description": "a jpush plugin for react native application", "main": "index.js", "scripts": { From 20352c4e5334f65e631388a032d2095bd6bf538b Mon Sep 17 00:00:00 2001 From: JoshLi <542938192@qq.com> Date: Thu, 18 Oct 2018 20:34:38 +0800 Subject: [PATCH 5/7] Update doc --- documents/api.md | 4 ++-- documents/api_en.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/documents/api.md b/documents/api.md index 03cb80bb..aa0ad4ec 100644 --- a/documents/api.md +++ b/documents/api.md @@ -11,8 +11,8 @@ * [setTags](#settags) * [cleanTags](#cleantags) * [sendLocalNotification](#sendlocalnotification) - * [clearLocalNotifications](#clearLocalNotifications) - * [removeLocalNotification](#removeLocalNotification) + * [clearLocalNotifications](#clearlocalnotifications) + * [removeLocalNotification](#removelocalnotification) * [clearAllNotifications](#clearallnotifications) * [clearNotificationById](#clearnotificationbyId) * [点击推送事件](#点击推送事件) diff --git a/documents/api_en.md b/documents/api_en.md index c327f70c..96db2430 100644 --- a/documents/api_en.md +++ b/documents/api_en.md @@ -13,8 +13,8 @@ * [Receive Notification event](#receive-notification-event) * [Receive Custom Message Event](#receive-custom-message-event) * [sendLocalNotification](#sendlocalnotification) - * [removeLocalNotification](#removeLocalNotification) - * [clearLocalNotifications](#clearLocalNotifications) + * [removeLocalNotification](#removelocalnotification) + * [clearLocalNotifications](#clearlocalnotifications) * [clearAllNotifications](#clearallnotifications) * [clearNotificationById](#clearnotificationbyId) * [iOS Only API](#ios-only-api) From a7b8389ed6fa932e2066cd8f9f41b4a9f11ea4eb Mon Sep 17 00:00:00 2001 From: huangminlinux <380108184@qq.com> Date: Fri, 19 Oct 2018 10:22:17 +0800 Subject: [PATCH 6/7] udpate api.md --- documents/api.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documents/api.md b/documents/api.md index aa0ad4ec..4b911931 100644 --- a/documents/api.md +++ b/documents/api.md @@ -210,7 +210,7 @@ JPushModule.clearLocalNotifications(); ``` var notificationId = 5; -JPushModule.removeLocalNotification(id); +JPushModule.removeLocalNotification(notificationId); ``` #### clearAllNotifications @@ -227,7 +227,7 @@ JPushModule.clearAllNotifications(); ``` var notificationId = 5; -JPushModule.clearNotificationById(id); +JPushModule.clearNotificationById(notificationId); ``` #### 点击推送事件 From 6befe18d5c7c806a36c4f8ad55da4bebd0fed0cb Mon Sep 17 00:00:00 2001 From: huangminlinux <380108184@qq.com> Date: Fri, 19 Oct 2018 10:58:45 +0800 Subject: [PATCH 7/7] iOS add removeLocalNotification clearLocalNotifications api --- index.js | 19 ++++++++----------- ios/RCTJPushModule/RCTJPushModule.m | 7 ++++++- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 48e0e53c..fbe43c7c 100644 --- a/index.js +++ b/index.js @@ -99,10 +99,15 @@ export default class JPush { } /** - * Android Only + * Android Only. + * 删除通知栏指定的推送。 */ static clearNotificationById (id) { - JPushModule.clearNotificationById(id) + if (Platform.OS == "android") { + JPushModule.clearNotificationById(id) + } else { + console.warn("iOS 没有提供该方法!") + } } /** @@ -631,22 +636,14 @@ export default class JPush { * 移除所有的本地通知 */ static clearLocalNotifications() { - if (Platform.OS == "android") { JPushModule.clearLocalNotifications() - } else { - - } } /** - * 移除指定的本地通知 + * 移除指定未触发的本地通知。 */ static removeLocalNotification(id) { - if (Platform.OS == "android") { JPushModule.removeLocalNotification(id) - } else { - - } } /** diff --git a/ios/RCTJPushModule/RCTJPushModule.m b/ios/RCTJPushModule/RCTJPushModule.m index c0db5150..9be6ec9f 100644 --- a/ios/RCTJPushModule/RCTJPushModule.m +++ b/ios/RCTJPushModule/RCTJPushModule.m @@ -870,12 +870,17 @@ - (void)didRegistRemoteNotification:(NSString *)token { } } -RCT_EXPORT_METHOD(clearNotificationById:(NSInteger)identify) { +RCT_EXPORT_METHOD(removeLocalNotification:(NSInteger)identify) { JPushNotificationIdentifier *pushIdentify = [[JPushNotificationIdentifier alloc] init]; pushIdentify.identifiers = @[[@(identify) description]]; [JPUSHService removeNotification: pushIdentify]; } +RCT_EXPORT_METHOD(clearLocalNotifications) { + [JPUSHService removeNotification: nil]; +} + + - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler { NSDictionary * userInfo = notification.request.content.userInfo; [JPUSHService handleRemoteNotification:userInfo];