SHARE
TWEET

index.js

a guest Oct 16th, 2019 145 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from "react";
  2. import OneSignal from 'react-native-onesignal';
  3.  
  4. import NavigationService from './utils/NavigationService';
  5.  
  6. import Routes from "./routes";
  7. import "./Config/ReactotronConfig";
  8.  
  9. console.disableYellowBox = true;
  10.  
  11. class App extends Component {
  12.   constructor(props) {
  13.     super(props);
  14.  
  15.     OneSignal.init('312312321321-213123-4d96-b473-756ytrgh567');
  16.  
  17.     OneSignal.addEventListener('received', this.onReceived);
  18.     OneSignal.addEventListener('opened', this.onOpened);
  19.     OneSignal.addEventListener('ids', this.onIds);
  20.  
  21.     OneSignal.inFocusDisplaying(2);
  22.  
  23.     OneSignal.requestPermissions({
  24.         alert: true,
  25.         badge: true,
  26.         sound: true
  27.     });
  28.   }
  29.  
  30.   componentWillUnmount() {
  31.     this.isUnmounted = true;
  32.  
  33.     OneSignal.removeEventListener('received', this.onReceived);
  34.     OneSignal.removeEventListener('opened', this.onOpened);
  35.     OneSignal.removeEventListener('ids', this.onIds);
  36.   }
  37.  
  38.   onReceived(notification) {
  39.     console.log("Notification received: ", notification);
  40. }
  41.  
  42. onOpened = (openResult) => { // AQUI QUERO NAVEGAR PARA OUTRA TELA EM VEZ DA TELA INICIAL
  43.     this.isNotification = true;
  44.  
  45.     let data = openResult.notification.payload.additionalData;
  46.     // ScreenName é o nome da tela que você definiu no StackNavigator
  47.     // this.props.navigation.navigate('ScreenName', data);
  48.      NavigationService.navigate('ScreenName', data);
  49. }
  50.  
  51. onRegistered(notifData) {
  52.     console.log("O dispositivo foi registrado para notificações push!", notifData);
  53. }
  54.  
  55. onIds(device) {
  56.     try {
  57.         AsyncStorage.setItem("@SC:deviceInfo", JSON.stringify(device));
  58.     } catch (error) {
  59.         console.log(error);
  60.     }
  61. }
  62.  
  63.   render(){
  64.     return(
  65.       <Routes ref={navigatorRef => {
  66.   NavigationService.setTopLevelNavigator(navigatorRef);
  67. }}  />
  68.     );
  69.   }
  70. }
  71.  
  72. export default App;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top