首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用React本机的自定义通知-本机-防火墙

使用React本机的自定义通知-本机-防火墙
EN

Stack Overflow用户
提问于 2019-10-07 18:00:04
回答 1查看 2.5K关注 0票数 2

我正在我的应用程序中使用react本机防火墙库实现推送通知,但我有一个问题。我需要在我的应用程序中挂载自定义通知,并在没有服务器发送标题/正文的情况下从React组装它们,我需要这些通知,并将应用程序放在后台并完全关闭。

我做了以下的尝试,但没有结果。

在我的索引中我注册了我的班级

代码语言:javascript
复制
  AppRegistry.registerHeadlessTask(
  "RNFirebaseBackgroundMessage",
  () => bgMessaging
 );

在我的JS课程中,我以以下方式对待

代码语言:javascript
复制
import firebase from "react-native-firebase";

import type { NotificationOpen } from "react-native-firebase";

export default async (notificationOpen: NotificationOpen) => {
  if (notificationOpen) {
    const notification = new firebase.notifications.Notification()
      .setTitle("Android Notification Actions")
      .setBody("Action Body")
      .setNotificationId("notification-action")
      .setSound("default")
      .android.setChannelId("notification-action")
      .android.setPriority(firebase.notifications.Android.Priority.Max);
    // Build an action
    const action = new firebase.notifications.Android.Action(
      "snooze",
      "ic_launcher",
      "My Test Action"
    );
    // This is the important line
    action.setShowUserInterface(false);
    // Add the action to the notification
    notification.android.addAction(action);

    // Display the notification
    firebase.notifications().displayNotification(notification);
  }

  return Promise.resolve();
};

但我没有成功。推送由固定标题和身体正常工作的消防基地发出的通知。

谢谢,为我的英语道歉。

EN

回答 1

Stack Overflow用户

发布于 2019-10-08 04:47:02

嗨,请试试下面的内容,

.setNotificationId(notificationOpen.notification.notificationId)

  • Change

  • .setNotificationId("notification-action")更改为.android.setChannelId("notification-action").android.setChannelId(notificationOpen.notification.android.channelId)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58274839

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档