React Native 本地计划推送通知在发布模式下不工作?

pbpqsu0x  于 2023-01-27  发布在  React
关注(0)|答案(1)|浏览(147)

我使用了"React原生推送通知":"^8.1.1",它在调试中工作得很好,但在发布APK中不显示通知,和(我的Android版本:十二)

siv3szwd

siv3szwd1#

如果Android目标SDK〉30,则React本机推送通知存在问题,您可以在github中检查此问题
要修复此问题,您需要使用此修补程序修补库:

diff --git a/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java b/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java
index ad3527b..447a540 100644
--- a/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java
+++ b/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java
@@ -455,8 +455,13 @@ public class RNPushNotificationHelper {
 
             int notificationID = Integer.parseInt(notificationIdString);
 
-            PendingIntent pendingIntent = PendingIntent.getActivity(context, notificationID, intent,
-                    PendingIntent.FLAG_UPDATE_CURRENT);
+            PendingIntent pendingIntent = null;
+            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
+                pendingIntent = PendingIntent.getActivity(context, notificationID, intent, PendingIntent.FLAG_MUTABLE);
+            }
+            else {
+                pendingIntent = PendingIntent.getActivity(context, notificationID, intent, PendingIntent.FLAG_UPDATE_CURRENT);
+            }
 
             NotificationManager notificationManager = notificationManager();

此解决方案已在github上提供。

相关问题