应用程序被杀死时不会触发onNotification()

Fad*_*adi 7 javascript push-notification react-native

我使用https://github.com/zo0r/react-native-push-notification得到推送通知和onNotification工作时,应用程序是aspected Active或在Background我收到的通知,但是当我杀死的应用程序,我只得到了通知和onNotification没有解雇任何一个可以请帮助我搜索一个解决方案但没有任何效果,当onNotification被解雇时,我增加了Android徽章计数是否有另一种方法来增加Android徽章时应用程序被杀?

"react-native": "0.55.3",
"react-native-push-notification": "3.0.2"
Run Code Online (Sandbox Code Playgroud)

我的代码

const options = {
        // (optional) Called when Token is generated (iOS and Android)
        onRegister: (token) => {
            this._TOKEN = token.token;
            this._addToPushChannels(channel);
        },

        onNotification: (notification) => {
            console.log(notification);
            if (notification['foreground']) {

            }

            //Notification from the background or when the app is killed
            if (!notification['foreground']) {
                if (Platform.OS !== 'ios' && Platform.Version < 26) {
                    this._messageCount++;
                    // console.log('this._messageCount ', this._messageCount);
                    let BadgeAndroid = require('react-native-android-badge');
                    BadgeAndroid.setBadge(this._messageCount);
                }
            }

            // required on iOS only (see fetchCompletionHandler docs: https://facebook.github.io/react-native/docs/pushnotificationios.html)
            notification.finish(PushNotificationIOS.FetchResult.NewData);

        },

        // ANDROID ONLY: GCM Sender ID (optional - not required for local notifications, but is need to receive remote push notifications)
        senderID: this._SENDER_ID,

        // IOS ONLY (optional): default: all - Permissions to register.
        permissions: {
            alert: true,
            badge: 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
         */
        requestPermissions: true,

    };

    PushNotification.configure(options);
Run Code Online (Sandbox Code Playgroud)

Rea*_*234 3

我并不肯定,但当我记得正确杀死(别名强制关闭)时,应用程序会禁用 Android (GCM) 推送通知网关中的 onNotification 功能(与 iOS/APNS 不同)。这是 Android 特意创建的一项功能,以便自愿强制关闭应用程序的用户不会受到通知的“困扰”。当手机重新启动或重新打开应用程序时,Xtify 服务将重新启动,并且将收到消息。

您可以做的是先安排通知。例如,当应用程序被强制关闭时,WhatsApp 经常会发布诸如“您可能有新通知”之类的通知,以提醒用户重新打开应用程序。

参考: