From 015afd8987366a8c76fd22683a46c12c1e93fc7e Mon Sep 17 00:00:00 2001 From: bashen1 Date: Thu, 16 Jul 2020 22:06:49 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E5=9C=A8=E7=83=AD=E5=90=AF=E5=8A=A8=E7=9A=84=E6=83=85=E5=86=B5?= =?UTF-8?q?=E4=B8=8B=EF=BC=8C=E7=82=B9=E5=87=BB=E6=8E=A8=E9=80=81=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E8=A7=A6=E5=8F=91addNotificationListener=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/cn/jiguang/plugins/push/JPushModule.java | 9 ++++++++- .../plugins/push/receiver/JPushModuleReceiver.java | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/cn/jiguang/plugins/push/JPushModule.java b/android/src/main/java/cn/jiguang/plugins/push/JPushModule.java index 21ab0fcb..c0b7bda2 100644 --- a/android/src/main/java/cn/jiguang/plugins/push/JPushModule.java +++ b/android/src/main/java/cn/jiguang/plugins/push/JPushModule.java @@ -5,7 +5,6 @@ import android.app.Application; import android.os.Bundle; import android.text.TextUtils; -import android.util.Log; import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.Callback; @@ -27,6 +26,7 @@ import cn.jiguang.plugins.push.receiver.JPushBroadcastReceiver; import cn.jpush.android.api.BasicPushNotificationBuilder; import cn.jpush.android.api.JPushInterface; +import cn.jpush.android.api.NotificationMessage; import cn.jpush.android.data.JPushLocalNotification; public class JPushModule extends ReactContextBaseJavaModule { @@ -35,6 +35,8 @@ public class JPushModule extends ReactContextBaseJavaModule { public static boolean isAppForeground = false; + public static NotificationMessage notificationMessage = null; + public JPushModule(ReactApplicationContext reactApplicationContext) { super(reactContext); reactContext = reactApplicationContext; @@ -59,6 +61,11 @@ public void init() { JPushHelper.sendEvent(JConstants.NOTIFICATION_EVENT, writableMap); JPushBroadcastReceiver.NOTIFICATION_BUNDLE = null; } + if (JPushModule.notificationMessage != null) { + WritableMap writableMap = JPushHelper.convertNotificationToMap(JConstants.NOTIFICATION_OPENED, notificationMessage); + JPushHelper.sendEvent(JConstants.NOTIFICATION_EVENT, writableMap); + JPushModule.notificationMessage = null; + } } @ReactMethod diff --git a/android/src/main/java/cn/jiguang/plugins/push/receiver/JPushModuleReceiver.java b/android/src/main/java/cn/jiguang/plugins/push/receiver/JPushModuleReceiver.java index 34ba7343..f7d65843 100644 --- a/android/src/main/java/cn/jiguang/plugins/push/receiver/JPushModuleReceiver.java +++ b/android/src/main/java/cn/jiguang/plugins/push/receiver/JPushModuleReceiver.java @@ -40,6 +40,7 @@ public void onNotifyMessageOpened(Context context, NotificationMessage notificat JLogger.d("onNotifyMessageOpened:" + notificationMessage.toString()); if (JPushModule.reactContext != null) { if (!JPushModule.isAppForeground) JPushHelper.launchApp(context); + JPushModule.notificationMessage = notificationMessage; WritableMap writableMap = JPushHelper.convertNotificationToMap(JConstants.NOTIFICATION_OPENED, notificationMessage); JPushHelper.sendEvent(JConstants.NOTIFICATION_EVENT, writableMap); } else { From 3decb77eb3d5e6c4a9a20b3a3698c03ce7a9c231 Mon Sep 17 00:00:00 2001 From: bashen1 Date: Sat, 18 Jul 2020 10:24:43 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8B=BC=E5=86=99?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.d.ts | 2 +- index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index a36e429f..9aed2d9e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -284,7 +284,7 @@ export default class JPush { /** * 自定义消息事件 */ - static addCustomMessagegListener( + static addCustomMessageListener( callback: Callback<{ /** * 唯一标识自定义消息的 ID diff --git a/index.js b/index.js index aa79258c..ebc46656 100644 --- a/index.js +++ b/index.js @@ -441,7 +441,7 @@ export default class JPush { * extras:对应 Portal 推送消息界面上的“可选设置”里的附加字段 * * */ - static addCustomMessagegListener(callback) { + static addCustomMessageListener(callback) { listeners[callback] = DeviceEventEmitter.addListener( CustomMessageEvent, result => { callback(result) From 9a856819a1d3fd07bcd1e64007b37e9fc35b70a9 Mon Sep 17 00:00:00 2001 From: bashen1 Date: Mon, 20 Jul 2020 21:22:01 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=83=85=E5=86=B5=E4=B8=8B=E5=AD=98=E5=9C=A8=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/jiguang/plugins/push/JPushModule.java | 50 ++++++++++++++----- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/android/src/main/java/cn/jiguang/plugins/push/JPushModule.java b/android/src/main/java/cn/jiguang/plugins/push/JPushModule.java index c0b7bda2..cc62195a 100644 --- a/android/src/main/java/cn/jiguang/plugins/push/JPushModule.java +++ b/android/src/main/java/cn/jiguang/plugins/push/JPushModule.java @@ -8,6 +8,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; @@ -29,7 +30,7 @@ import cn.jpush.android.api.NotificationMessage; import cn.jpush.android.data.JPushLocalNotification; -public class JPushModule extends ReactContextBaseJavaModule { +public class JPushModule extends ReactContextBaseJavaModule implements LifecycleEventListener { public static ReactApplicationContext reactContext; @@ -39,6 +40,7 @@ public class JPushModule extends ReactContextBaseJavaModule { public JPushModule(ReactApplicationContext reactApplicationContext) { super(reactContext); + reactApplicationContext.addLifecycleEventListener(this); reactContext = reactApplicationContext; } @@ -378,7 +380,7 @@ public void addLocalNotification(ReadableMap readableMap) { return; } String notificationID = readableMap.getString(JConstants.MESSAGE_ID); - if(notificationID==null || TextUtils.isEmpty(notificationID)){ + if (notificationID == null || TextUtils.isEmpty(notificationID)) { JLogger.w(JConstants.PARAMS_ILLEGAL); return; } @@ -405,7 +407,7 @@ public void removeLocalNotification(ReadableMap readableMap) { } if (readableMap.hasKey(JConstants.MESSAGE_ID)) { String notificationID = readableMap.getString(JConstants.MESSAGE_ID); - if(notificationID==null || TextUtils.isEmpty(notificationID)){ + if (notificationID == null || TextUtils.isEmpty(notificationID)) { JLogger.w(JConstants.PARAMS_ILLEGAL); return; } @@ -469,33 +471,33 @@ public void deleteGeofence(ReadableMap readableMap) { } @ReactMethod - public void clearAllNotifications(){ + public void clearAllNotifications() { JPushInterface.clearAllNotifications(reactContext); } @ReactMethod - public void clearNotificationById(ReadableMap readableMap){ - if (readableMap == null){ + public void clearNotificationById(ReadableMap readableMap) { + if (readableMap == null) { JLogger.w(JConstants.PARAMS_NULL); return; } - if (readableMap.hasKey(JConstants.NOTIFICATION_ID)){ + if (readableMap.hasKey(JConstants.NOTIFICATION_ID)) { Integer id = readableMap.getInt(JConstants.NOTIFICATION_ID); - JPushInterface.clearNotificationById(reactContext,id); - }else { + JPushInterface.clearNotificationById(reactContext, id); + } else { JLogger.w("there are no " + JConstants.GEO_FENCE_ID); } } @ReactMethod - public void setPowerSaveMode(boolean bool){ - JPushInterface.setPowerSaveMode(reactContext,bool); + public void setPowerSaveMode(boolean bool) { + JPushInterface.setPowerSaveMode(reactContext, bool); } @ReactMethod - public void isNotificationEnabled(Callback callback){ + public void isNotificationEnabled(Callback callback) { Integer isEnabled = JPushInterface.isNotificationEnabled(reactContext); - if (callback == null){ + if (callback == null) { JLogger.w(JConstants.CALLBACK_NULL); return; } @@ -545,4 +547,26 @@ public void onActivityDestroyed(Activity activity) { }); } + @Override + public void onHostResume() { + + } + + @Override + public void onHostPause() { + + } + + @Override + public void onHostDestroy() { + JLogger.d("onHostDestroy"); + notificationMessage = null; + } + + @Override + public void onCatalystInstanceDestroy() { + super.onCatalystInstanceDestroy(); + JLogger.d("onCatalystInstanceDestroy"); + notificationMessage = null; + } } From 300889415e389684fdd15d4665a7b110fbb5b20d Mon Sep 17 00:00:00 2001 From: bashen1 Date: Wed, 23 Sep 2020 10:24:10 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E7=A7=81=E6=9C=89=E5=8C=96jpush?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index bb88b7e4..dc1dc6e1 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,15 @@ { - "name": "jpush-react-native", + "name": "react-native-mjpush", "description": "React Native JPush component for Android and iOS", - "homepage":"https://github.com/jpush/jpush-react-native", + "homepage":"https://github.com/bashen1/jpush-react-native", "main": "index.js", "types": "index.d.ts", "license": "ISC", "author": "wicked.tc130", - "version": "2.8.1", + "version": "2.8.2", "repository": { "type": "git", - "url": "https://github.com/jpush/jpush-react-native" + "url": "https://github.com/bashen1/jpush-react-native" }, "keywords": [ "react-native",