React-native-firebase: In react-native debug mode notification().onNotification() is working fine but in release mode it's not working. In release and simulator mode, react-native app messaging().onMessage() handler is triggered I don't know why this problem arises. please provide solution.

Created on 26 Nov 2019  路  5Comments  路  Source: invertase/react-native-firebase

here is my firebase handler
const displayNotification = (notification) => {
if (Platform.OS === 'android') {
const localNotification = new firebase.notifications.Notification({
sound: 'default',
show_in_foreground: true,
}).setNotificationId(notification.notificationId)
.setTitle(notification.title)
.setSubtitle(notification.subtitle)
.setBody(notification.body)
.setData(notification.data)
.android.setChannelId('bill_delivery') // e.g. the id you chose above
.android.setSmallIcon('ic_launcher') // create this icon in Android Studio
//.android.setColor() // you can set a color here
.android.setPriority(firebase.notifications.Android.Priority.High);

firebase.notifications()
  .displayNotification(localNotification)
  .catch(err => console.log(err));

} else {
console.log(":FOR IOS :")
const localNotification = new firebase.notifications.Notification({
sound: 'default',
show_in_foreground: true,
}).setNotificationId(notification.notificationId)
.setTitle(notification.title)
.setSubtitle(notification.subtitle)
.setBody(notification.body)
.setData(notification.data)

firebase.notifications()
  .displayNotification(localNotification)
  .catch(err => console.log(err));

}
}

const subscribeToNotificationListeners = (onNotificationOpenCallback) => {
//CREATING CHANNEL FOR ANDROID
console.log("Subscribe to notification....")
if (Platform.OS === 'android') {
const channel = new firebase.notifications.Android.Channel(
'bill_delivery', // To be Replaced as per use
'Bill Delivery', // To be Replaced as per use
firebase.notifications.Android.Importance.Max
).setDescription('This channel for Bill Delivery notification BillMe App.');
firebase.notifications().android.createChannel(channel);
}
//ON NOTIFICATION REVEIVED
firebase.notifications().onNotification((notification) => {
console.log("*On Notification*")
displayNotification(notification)
});

// ON CLICK ON NOTIFICATION AND APP OPEN
firebase.notifications().onNotificationOpened(onNotificationOpenCallback);

// firebase.notifications().getInitialNotification(notification=>{
// console.log(notification)
// displayNotification(notification)
// })

firebase.messaging().onMessage((message) => {
try {
const {billUid, brandName, displayAddress, shortId, signedURL, transactionType } = message._data;
const notifyObj={
notificationId:message._messageId,
title:brandName,
body:'New Bill Arrived into your bucket',
data:{billUid,brandName,displayAddress,shortId,signedURL,transactionType}
}
displayNotification(notifyObj)
} catch (e) {
console.log(e)
}
console.log("Notification arrived*")
});

}

//If Token found then send its to sever
const sendFCMTokenToServer = async (pushNotificationToken) => {
console.log(pushNotificationToken)
NetInfo.fetch().then(async state => {
if (state.isConnected || state.isInternetReachable) {
try {
const token = await getTokenFromLocal();
const url = ${baseUrl}/auth/pushnotificationtoken
const response = await axios.post(url, { pushNotificationToken }, { headers: { authtoken: token } });
console.log(response)
console.log("*FCM Token Send successfully **")
} catch (e) {
console.log(e);
}
} else {
showingToast.internetConnectivity('Internet Connection is not available')
}
})

}

export const getFirebaseToken = async (onClickNotifiy) => {
try {
console.log(":GETTing firebase:")
if (Platform.OS === 'android') {
//Adding listener
subscribeToNotificationListeners(onClickNotifiy);
//if token not found then it's saved in local database
if (await fcmTokenStatus() === null) {
const fcmToken = await firebase.messaging().getToken();
if (fcmToken) {
console.log(":fcm token:");
console.log(fcmToken);
await storeFcmToken(fcmToken)
sendFCMTokenToServer(fcmToken);
}
}
} else {
const enabled = await firebase.messaging().hasPermission();
if (enabled) {
try {
subscribeToNotificationListeners(onClickNotifiy);
} catch (error) {
console.log('error : ', error);
}
} else {
try {
firebase.messaging().requestPermission()
.then(async() => {
subscribeToNotificationListeners(onClickNotifiy);
const fcmToken = await firebase.messaging().getToken();
if (await fcmTokenStatus() === null) {
await storeFcmToken(fcmToken)
sendFCMTokenToServer(fcmToken);
}
})
.catch(error => {
console.log('error :', error)
});
} catch (e) {
console.log('error :', error)
}
}
}
} catch (e) {
console.log(e)
showingToast.errorToast('Please uninstall app and install again')
}

}

Stale

Most helpful comment

I read from some other issue that it is something to do with iOS 13. Can someone valdate?

All 5 comments

I am having the same problem.
On Android the onNotification is triggered, But on ios onMessage is triggered ?
It was working perfectly 2 weeks ago and i didn't edit the code since then ,
Is this a problem in the package itself or is there a new ios update i should know about ??

I read from some other issue that it is something to do with iOS 13. Can someone valdate?

Hello 馃憢, to help manage issues we automatically close stale issues.
This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?

This issue will be closed in 15 days if no further activity occurs.
Thank you for your contributions.

Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.

Having the same issue.

Was this page helpful?
0 / 5 - 0 ratings