本地反应本机推送通知不起作用

问题描述

我在使用本地 react-native-push-notification 时遇到问题,如果应用程序处于打开状态且 fcm 通知未触发,则无法正常工作。这是我的代码...

PushNotification.configure({
      onRegister: function (token) {
        console.log("[localnotificationService] onRegister:",token);
      },onNotification: function (notification) {
        console.log("[localnotificationService] onNotification:",notification);
        if (!notification?.data) { return  }
        // notification.userInteraction = true;
        if(notification.userInteraction){ onopenNotification(Platform.OS === 'ios' ? notification.data.item ? notification.data.item : notification.data : notification.data) }
        else { onopenNotification({}) }
        if (Platform.OS === 'ios') {
          // (required) Called when a remote is received or opened,or local notification is opened
          notification.finish(PushNotificationIOS.FetchResult.NoData)
        }
      },// IOS ONLY (optional): default: all - Permissions to register.
      permissions: {
        alert: true,sound: true,},// Should the initial notification be popped automatically
      // default: true
      popInitialNotification: true,/**
       * (optional) default: true
       * - Specified if permissions (ios) and token (android and ios) will requested or not,* - if not,you must call PushNotificationsHandler.requestPermissions() later
       * - if you are not using remote notification or do not have Firebase installed,use this:
       *     requestPermissions: Platform.OS === 'ios'
       */
      requestPermissions: true,})

    PushNotification.localnotification({
          /* Android Only Properties */
          ...this.buildAndroidNotification(id,title,message,data,options),/* iOS and Android properties */
          ...this.buildioSNotification(id,/* iOS and Android properties */
          id: `${id}`,title: title || "",message: message || "",playSound: options.playSound || false,soundName: options.soundName || 'default',userInteraction: true // BOOLEAN: If the notification was opened by the user from the notification area or not
    });

为什么会这样?感谢您在这方面的帮助,谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)