react-native-push-notification
react-native-push-notification copied to clipboard
Which method is used when we press a only local notification comes when app is in foreground?
Question
I'm using Firebase for push notifications in React Native. As you know that when the application is in the foreground then notification does not show in the notification tray but we can receive in onMessage() Handler provided by firebase. So to show notification in notification tray, I'm using this library to manually produce local notification. So what I need right now when the user is using the application and the application is in the foreground, clicking on that notification will redirect the user to a specific screen in the application. Can anybody please help me out?
Maybe you need to use React Navigation and the method onAction or onNotification of React Native Push Notification.
Both of these methods work for remote notifications too which I do not want to do. Through this, I'm integrating local push notifications but the methods you are saying if I will implement those then they will trigger as well on remote notifications which I do not want to do.
In my case, the app start popping local push notification after I send a remote push notification in background state. I don't know why but after this the local push notification started works.
I solve it: android/app/src/main/AndroidManifest.xml
<meta-data
android:name="com.dieam.reactnativepushnotification.default_notification_channel_id"
android:value="default_channel_name" />
and...
useEffect(()=>
PushNotification.createChannel(
{
channelId: 'default_channel_name', // (required)
channelName: 'default_channel_name', // (required)
},
created => console.debug(`createChannel returned '${created}'`),
);
const unsubsceribeRemoteMessaging = firebase
.messaging()
.onMessage(message => {
PushNotification.localNotification({
...message,
...message.data,
...message.notification,
channelId: 'default_channel_name'',
message: message.notification.body,
ignoreInForeground: false,
smallIcon: 'ic_launcher',
// your optionals props...
});
});
return () => {
unsubsceribeRemoteMessaging();
};
},[])
Hermanyo in this case, we can generate the local notification that is fine. What I want clicking on local push notification will go to another screen and clicking remote notification will take it to another screen. I want click push notification handler will only work for local push notification. Right now, it's working for both local and push notification.
On Mon, Apr 5, 2021, 10:32 PM Hermanyo H. @.***> wrote:
I solve it: android/app/src/main/AndroidManifest.xml
and...
useEffect(()=> PushNotification.createChannel( { channelId: 'default_channel_name', // (required) channelName: 'default_channel_name', // (required) }, created => console.debug(
createChannel returned '${created}'
), );const unsubsceribeRemoteMessaging = firebase .messaging() .onMessage(message => { PushNotification.localNotification({ ...message, ...message.data, ...message.notification, channelId: 'default_channel_name'', message: message.notification.body, ignoreInForeground: false, smallIcon: 'ic_launcher', // your optionals props... }); });
return () => { unsubsceribeRemoteMessaging(); };
},[])
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/zo0r/react-native-push-notification/issues/1913#issuecomment-813522502, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJ3R4UBZNPZK55YCWO7JPA3THHX3FANCNFSM4ZL6QI3Q .
Hi @Haseeba393 , I have implemented this library for local notification and it doesn't have separate methods for Remote or local notifications, you can only catch both in one method i.e
// (required) Called when a remote or local notification is opened or received
onNotification: handler.onNotification.bind(handler),
I'm struggling with redirecting the user to a specific screen, when i receive a notification and on click of that , i want user to redirect to particular screen. I have followed this example only when you schedule in particular class, the callback methods are executing. I have login screen in middle, how do i take user to particular screen where notification schedule happened at some other class. Any idea, please help, Thanks.
Actually brother I'm implementing Push notifications using Firebase and Firebase onMessage() handler is only catching the notification but not showing any notification in the notification tray. The only thing I can do is to implement Local Notification But implementing Local Notification means cathing both local and remote notification which I don't want. Regarding your question, how to redirect to a specific screen, then the best way is to put handlers to the very start of the application. Then get the notification on which you are clicking in the respective handler and then using navigation.navigate() or using deep linking you can navigate to specific screen.
On Tue, 6 Apr 2021 at 16:59, Madhu Kunal @.***> wrote:
Hi @Haseeba393 https://github.com/Haseeba393 , I have implemented this library for local notification and it doesn't have separate methods for Remote or local notifications, you can only catch both in one method i.e
// (required) Called when a remote or local notification is opened or received onNotification: handler.onNotification.bind(handler),
I'm struggling with redirecting the user to a specific screen, when i receive a notification and on click of that , i want user to redirect to particular screen. I have followed this example https://github.com/zo0r/react-native-push-notification/tree/master/example only when you schedule in particular class, the callback methods are executing. I have login screen in middle, how do i take user to particular screen where notification schedule happened at some other class. Any idea, please help, Thanks.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/zo0r/react-native-push-notification/issues/1913#issuecomment-814062799, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJ3R4UA6HOECKK2BWIIADFDTHLZS3ANCNFSM4ZL6QI3Q .
You have probably solved it, but i'll leave a solution for someone who might need it. You can use "foreground" property of notification object passed to onNotification and only apply your logic if foreground: true.
@warryr No, I was not able to solve this problem. What I have done that on receiving notification, I was updated application UI according to it rather than displaying notification in notification tray
Any solution for this issue?