I want to push another page when the user touch notification
in another problem if i push an notification with actions like: actions: '["Accept", "Reject"]' it doesnt show the action selected if app is foreground.
please, help me i try this so hard without results
import React from 'react';
import AppNavigator from './AppNavigator';
//PUSH NOTIFICATION
var PushNotification = require('react-native-push-notification');
PushNotification.configure({
// (optional) Called when Token is generated (iOS and Android)
onRegister: function(token) {
console.log( 'TOKEN:', token );
//console.warn('TOKEN:', token.token);
},
// (required) Called when a remote or local notification is opened or received
onNotification: function(notification) {
console.log( 'NOTIFICATION:', notification );
this.props.navigation.navigate('Details');
// process the notification
// required on iOS only (see fetchCompletionHandler docs: https://facebook.github.io/react-native/docs/pushnotificationios.html)
//notification.finish(PushNotificationIOS.FetchResult.NoData);
},
// ANDROID ONLY: GCM or FCM Sender ID (product_number) (optional - not required for local notifications, but is need to receive remote push notifications)
senderID: "MYSENDERID",
// 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,
});
//END
export default class App extends React.Component {
render() {
return (
<AppNavigator/>
);
}
}
@JoaquinDelPrado How did you solve this? As I am also facing the similar issue.
Wich is your problem?
@saadmutahar take this as an example:
`export default class Login extends React.Component {
constructor(props){
super(props);
this.setToken = this.setToken.bind(this);
this.handleNotification = this.handleNotification.bind(this);
}
setToken(token){
//your logic here, save the token
};
handleNotification(notification){
//your logic here,
console.warn(notification);
let isBackground = notification.foreground;
if(isBackground == true){
this.props.navigation.navigate('Home');
}
};
async componentDidMount(){
//PUSH NOTIFICATION
var that = this;
PushNotification.configure({
onRegister: function(token) {
//Funci贸n para guardar token
that.setToken(token);
},
onNotification: function(notification) {
//Funci贸n para manejar notificaciones
that.handleNotification(notification);
//notification.finish(PushNotificationIOS.FetchResult.NoData); //Solo para IOS
},
senderID: "30438xxxxxxx",
permissions: {
alert: true,
badge: true,
sound: true
},
popInitialNotification: true,
requestPermissions: true,
});
}
@JoaquinDelPrado thank you for you help.
Kindly if you know that can we trigger onNotification function by tapping or clicking on local Notification in IOS?
Thanks
@saadmutahar if you're follow my code in handleNotification function you can do console.warn(notification) and get the notification data. But i never test in IOS, sorry :(
@JoaquinDelPrado handleNotification method do i need to write in every screen or else in App.js it is enough?
For Ex: in my app there is login, newfeed, request, settings, and app.js. If i was in settings and i received a notification. Now i need to redirect to some specfic page(for ex: newsfeed) on tap of notification. so where i need to write that handleNotification either in settings Page or App.js is enough. if app.js is enough will handleNotifcation be call everytime on tap of notification.Please help
if you're using the App and a notification arrive you want redirect immediately to the another screen? or just if the user touch the notification? in both cases should be work using handleNotification in App. You have to see wich is the information (you can do a console.warn(notification)) and decide what you want to do.
Please let me know if it works
@JoaquinDelPrado i get it. if i was in the settings page and if i get notification on click of notification i will navigate to newfeed screen. what my doubt is handleNotification function is there right that function where i need to write either in settings screen or route component APP.js
@JoaquinDelPrado can you please respond
When an notification arrives it shot an event, this event its the notification so the component will be listen that. App.js initialize the App so may be listen the event. In another way you can test it, paste my example code in your App.js and go to the setting screen, its important add the console.warn(notification) in handleNotification function (that way you know the notification comes) then send a push notification and touch it, you may get a warning log with the data of notification.
that it's the process. I hope I help you
Was there a solution for this?
Was there a solution for this?
Sure, take this example
async componentDidMount(){
//PUSH NOTIFICATION
var that = this;
PushNotification.configure({
onRegister: function(token) {
//Funci贸n para guardar token
that.setToken(token);
},
onNotification: function(notification) {
//Funci贸n para manejar notificaciones
that.handleNotification(notification);
//notification.finish(PushNotificationIOS.FetchResult.NoData); //Solo para IOS
},
senderID: "30438xxxxxxx",
permissions: {
alert: true,
badge: true,
sound: true
},
popInitialNotification: true,
requestPermissions: true,
});
}
Most helpful comment
@saadmutahar take this as an example: