i'm using https://github.com/zo0r/react-native-push-notification
to get push notifications and the onNotification is working as aspected when the app is Active
or in the Background
i'm receiving the notification, but when i kill the app i only get the notification and the onNotification is not fired can any one please help i searched for a solution but nothing worked, i'm increasing the Android badges count when the onNotification is fired is there another way to increasing Android badges when the app is killed?
"react-native": "0.55.3",
"react-native-push-notification": "3.0.2"
my code
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);
I am not positive but when I remember correctly killing (alias force closing) an app disables the onNotification functionality in Android (GCM) Push Notification Gateway (unlike iOS/APNS). This is a Android-wise feature and intentionally created so that users who willingly force close their app dont get "bothered" with notifications. The Xtify service will be restarted and messages will be received when either the phone is restarted or the app is reopened.
What you could do is schedule notifications apriori. WhatsApp, for instances, frequently posts notifications like: "You may have new notifications" when the app is forced closed to remind the user to reopen the app.
References:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With