, когда я использую реагирующее-push-уведомление, я управляю, чтобы получить текст моего уведомления следующим образом:
componentWillMount() {
var _this = this;
PushNotification.configure({
onRegister: function(token) {
_this.props.InitToken(token.token);
},
onNotification: function(notification) {
setTimeout(() => {
if(!notification['foreground']){
_this.props.InitNotif(notification['message']);
}
}, 1);
PushNotification.localNotificationSchedule({
title: 'Notification with my name',
message: notification['name'], // (required)
date: new Date(Date.now()) // in 60 secs
});
},
// ANDROID ONLY: GCM Sender ID (optional - not required for local notifications, but is need to receive remote push notifications)
senderID: "YourID",
});
}
где
_this.props.InitToken(token.token);
и
_this.props.InitNotif(notification['message']);
- это функция на основе избыточности, которая обновляет ваше состояние с помощью токена уведомления и сообщения. Когда ваше состояние будет обновлено с уведомлением, вы можете изменить маршрут или отобразить сообщение на экране.
PS:
Я не знаю, был ли это хороший способ, но я работал
componentWillMount () амортизируется.