【问题标题】:react-native-firebase receiving notification when app in runningreact-native-firebase 在应用程序运行时收到通知
【发布时间】:2018-12-09 17:42:29
【问题描述】:

我正在使用 react-native-firebase 实现推送通知。所以,我正在测试云消息传递。当屏幕关闭并处于后台时,我可以收到通知。但是,当应用程序运行时,我无法收到通知。我的代码有什么问题还是我需要添加一些代码?

async createNotificationListeners() {

    this.notificationListener = firebase.notifications.onNotification((notification) => {
        const { title, body } = notification;
        this.showAlert(title, body);
    });

    this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen) => {
        const { title, body } = notificationOpen.notification;
        this.showAlert(title, body);
    });

    const notificationOpen = await firebase.notifications().getInitialNotification();
    if (notificationOpen) {
        const { title, body } = notificationOpen.notification;
        this.showAlert(title, body);
    }

    this.messageListener = firebase.messaging().onMessage((message) => {
        //process data message
        console.log(JSON.stringify(message));
    });
}

componentWillUnmount() {
    this.notificationListener();
    this.notificationOpenedListener();
}

【问题讨论】:

  • 您为什么要向此时正在使用您的应用的用户发送通知?这似乎是一种非常烦人的用户体验。如果您想在您的应用程序使用期间收到某种通知,请尝试实现某种应用程序内通知,该通知会在应用程序使用期间出现一些自然停顿

标签: android firebase react-native notifications


【解决方案1】:

推送通知不能发生在应用中,因为这实际上违背了它的目的。推送通知的合理definition 是在没有来自客户端的特定请求的情况下将信息从软件应用程序传递到计算设备。在应用程序使用期间,客户端将向服务器发出特定请求。您应该以不同的方式处理通知,例如使用带编号的图标。您还可以探索 Firebase In-App Messaging 以获得更吸引人的体验。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多