как перенаправить на экран, когда приложение открывается из push-уведомлений в реагировать родной - PullRequest
0 голосов
/ 14 мая 2019

Я работаю над собственным приложением реагирования с библиотекой aws-ampify https://aws -amplify.github.io / docs / js / push-уведомления . Когда я нажимаю push-уведомление, мое приложение должно перенаправление на экран уведомлений. Я не получаю реквизиты навигации, когда открываю приложение из уведомлений, поэтому я использую это для работы без проп https://reactnavigation.org/docs/en/navigating-without-navigation-prop.html, но все равно получаю эту ошибку "undefined не является объектом (оценка 't.dispatch') ". Я использую реагирующую навигацию в своем приложении

 import PushNotification from '@aws-amplify/pushnotification';
 import NotificationList from './NotificationList';
 import NavigationService from './NavigationService';

   Analytics.configure(awsmobile);

  PushNotification.configure(awsmobile);


if(Platform.OS === 'android'){


PushNotification.onNotification((notification) => {

    // console.log('in app notification : Outside App', notification);

    Auth.currentAuthenticatedUser({
      bypassCache: false  // Optional, By default is false. If set to true, this call will send a request to Cognito to get the latest user data
    }).then(user => {

    console.log('Current user : Outside App', user.attributes.sub)

    const currentDate = new Date();

    const todayDate = moment(currentDate).format("YYYY-MM-DD")

    var todayTime = moment().format('HH:mm:ss')

    const notificationDetails = {
        userId: user.attributes.sub,
        userTitle: notification.title,
        userBody: notification.body,
        userDate: todayDate,
        userTime: todayTime,
    };

    console.log("notificationDetails outside", notificationDetails)

    API.graphql(graphqlOperation(createUserNotification, { input: notificationDetails }))
        .then(response => {

            console.log(JSON.stringify(response, null, 2));
        })
        .catch(err => {
            console.log('Error Saving Details...', err);
            this.setState({ showActivityIndicator: false });
    });

  });

});

  PushNotification.onNotificationOpened((notification) => {

        const b = new Home();

        console.log('onNotificationOpened 1');

        b._handleNotificationOpen(notification)


  });

}

 class Home extends React.Component {


 constructor(props) {
 super(props);

  global.ShowRecordVar = "12"

  this._handleNotificationOpen =  
  this._handleNotificationOpen.bind(this);



  this.state = {
    apiResponse: 0,
    loading: true,

  }
 }

_handleNotificationOpen = (notification) => {

 if (notification["pinpoint.deeplink"]) {

    NavigationService.navigate('NotificationList',{notification});

 }
}

//Some More Codes

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...