Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. import {Provider} from 'react-redux';
  2. import store from './src/redux/store';
  3. import AppViewContainer from './src/modules/AppViewContainer';
  4. import React, {Component} from 'react';
  5. import {AppRegistry} from 'react-native';
  6. import {Colors} from 'react-native-ui-lib';
  7. import {setConfiguration} from '@utils/configuration';
  8. import OneSignal from 'react-native-onesignal';
  9. import * as notificationsActions from '@modules/notifications/NotificationsState';
  10. import {NavigationActions} from 'react-navigation';
  11.  
  12. setConfiguration('clientID', '169D63FB430EA6782110AD15C4647E5E246323AB5C07611B9997A573C768BFE7');
  13.  
  14. console.disableYellowBox = true;
  15.  
  16. Colors.loadColors({
  17. verde: '#1ABC9C',
  18. verdeLight: '#D9FFF7',
  19. verdeDark: '#16A085',
  20. vermelho: '#701E00',
  21. cinza: '#A6ABAB',
  22. });
  23.  
  24. class VerdeCidadao extends Component {
  25. constructor() {
  26. super();
  27. this.onReceived = this.onReceived.bind(this);
  28. this.onOpened = this.onOpened.bind(this);
  29. this.onIds = this.onIds.bind(this);
  30. // this.onEmailRegistrationChange = this.onEmailRegistrationChange.bind(this);
  31. }
  32. async componentDidMount() {
  33. OneSignal.addEventListener('received', this.onReceived);
  34. OneSignal.addEventListener('opened', this.onOpened);
  35. OneSignal.addEventListener('ids', this.onIds);
  36. }
  37.  
  38. componentWillUnmount() {
  39. OneSignal.removeEventListener('received', this.onReceived);
  40. OneSignal.removeEventListener('opened', this.onOpened);
  41. OneSignal.removeEventListener('ids', this.onIds);
  42. }
  43.  
  44. componentWillMount() {
  45. OneSignal.init('c4d77f04-82dd-4b35-b1a0-6520f4f34bf6');
  46. OneSignal.setRequiresUserPrivacyConsent(false);
  47. OneSignal.provideUserConsent(true);
  48. OneSignal.setLogLevel(6, 0);
  49. OneSignal.setLocationShared(true);
  50. OneSignal.inFocusDisplaying(2);
  51. OneSignal.setSubscription(true);
  52. }
  53.  
  54. onReceived(notification) {
  55. const id = notification.payload.notificationID;
  56. store.dispatch(notificationsActions.onReceivedNotifications(id));
  57. }
  58.  
  59. onOpened(openResult) {
  60. const id = openResult.notification.payload.notificationID;
  61. store.dispatch(NavigationActions.navigate({routeName: 'MainMenu'}));
  62. store.dispatch(notificationsActions.detailsNotifications(id, 1));
  63. }
  64.  
  65. onIds(device) {
  66. console.log('ON IDS');
  67. this.registerDeviceOneSignal();
  68.  
  69. // OneSignal.getPermissionSubscriptionState(status => {
  70. // console.log(status);
  71. // });
  72. }
  73.  
  74. registerDeviceOneSignal() {
  75. const {id, subscribed} = store
  76. .getState()
  77. .get('auth')
  78. .toJS().user;
  79. OneSignal.setSubscription(true);
  80. if (id) {
  81. OneSignal.setExternalUserId(id);
  82. OneSignal.sendTags({cidadaoId: id});
  83. }
  84. }
  85.  
  86. render() {
  87. return (
  88. <Provider store={store}>
  89. <AppViewContainer />
  90. </Provider>
  91. );
  92. }
  93. }
  94.  
  95. AppRegistry.registerComponent('VerdeCidadao', () => VerdeCidadao);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement