首页 > 解决方案 > React Native 推送通知 iOS - 待处理通知的数量

问题描述

我将 React Push Notifications ( https://github.com/zo0r/react-native-push-notification ) 与 localNotificationSchedule 一起用于启动通知,但在 iOS 中,推送通知的数量永远不会被破坏。

即使我选择通知,数字也不会下降......

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

在此处输入图像描述

我的代码:

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 {
...

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

有谁知道为什么会发生这种情况?

标签: iosreact-nativepush-notification

解决方案


推荐阅读