React Native推送通知iOS-待处理的通知数量

问题描述 投票:0回答:1

我在本地通知中使用带有localNotificationSchedule的React推送通知(https://github.com/zo0r/react-native-push-notification),但是在iOS中,推送通知的数量从未被破坏。

即使我选择了通知,号码也不会减少...

此号码:(在桌面图标中)

enter image description here

我的代码:

import PushNotificationIOS from "@react-native-community/push-notification-ios";

var PushNotification = require("react-native-push-notification");

  PushNotification.configure({

    onRegister: function(token) {
      console.log("TOKEN:", token);
    },

    onNotification: function(notification) {
      console.log("NOTIFICATION:", notification);

        let num = 0;
        if (Platform.OS === 'ios') {
          num = notification.data.num;
        } else {
          num = notification.userInfo.num;
        }        

        switch(num) {

          case 1:
            NavigationService.navigate('OnePage');
            break;
          case 2:
            NavigationService.navigate('TwoPage');
            break;     
          default:
            NavigationService.navigate('Home');

      }

      if (Platform.OS === 'ios') {
        notification.finish(PushNotificationIOS.FetchResult.NoData);
      }
    },

    senderID: "YOUR GCM (OR FCM) SENDER ID",

    permissions: {
      alert: true,
      badge: true,
      sound: true
    },

    popInitialNotification: true,


    requestPermissions: true    
  });

class IndexNavigator extends React.Component {
...

显然,根据文档,此代码应该正确,但是即使我按了通知并将我重定向到我想要的页面。图标中的数字从不减少,而总是增加。

任何人都知道为什么会发生这种情况吗?

ios react-native push-notification
1个回答
0
投票
我正在发送此有效负载,它对我有用:

{ "to" : "ddUYveNp4QE....", "notification" : { "body" : "un nouveau partage", "title" : "un partage de contact reçu", "priority" : "high", "vibration":true, "sound": "Enabled", "badge":1, "requireInteraction": true, "click_action": "fcm.ACTION.HELLO" }, "data" : { "body" : "nouvelle opportunité", "title" : "un nouveau partage", "content_available" : true, "priority" : "high" } }

徽章是ios图标应用程序中显示的数字。尝试在徽章中发送变量并显示用户尚未看到的通知数
© www.soinside.com 2019 - 2024. All rights reserved.