微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决本地反应本机推送通知不起作用

我在使用本地 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 举报,一经查实,本站将立刻删除。