小编Rey*_*bha的帖子

React Native Firebase,当应用程序处于前台时不显示通知,仅在 Android 8 或更高版本上使用 bundle build

我有一个带有 react-native-firebase 通知的应用程序,消息已成功接收,通知已成功创建并显示在 Android Nougat 或更旧版本、Android Oreo 或更高版本上我添加了 channelId 它在使用 react-native run 时运行良好- android,但是当使用 bundle (cd android && ./gradlew installRelease) 时,我的通知不仅仅在 Android Oreo 或更高版本的前台显示,在后台工作。不知道问题出在消息侦听器上还是在创建通知时。这是我的代码...

我在获得权限后调用下面的函数,当应用程序在前台时收听消息

export const listening_message = () => {
return firebase.notifications().onNotification((notification) => {
    display_notification({
        notification_param: {
            sound: 'default',
            show_in_foreground: true,
        },
        title: notification.title,
        subtitle: notification.subtitle,
        body: notification.body,
        data: notification.data,
    });
});
}
Run Code Online (Sandbox Code Playgroud)

那么这是显示通知的代码

async function display_notification(parameter) {
let realmUser = await Realm.open(RealmData.User);

if(realmUser.objects(RealmDataName.User).length > 0) {
    let realmNotification = await Realm.open(RealmData.NotificationID);

    if(realmNotification.objects(RealmDataName.NotificationID).length == 0) {
        realmNotification.write(() => …
Run Code Online (Sandbox Code Playgroud)

javascript android-notifications firebase react-native react-native-firebase

5
推荐指数
0
解决办法
2792
查看次数