Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {Provider} from 'react-redux';
- import store from './src/redux/store';
- import AppViewContainer from './src/modules/AppViewContainer';
- import React, {Component} from 'react';
- import {AppRegistry} from 'react-native';
- import {Colors} from 'react-native-ui-lib';
- import {setConfiguration} from '@utils/configuration';
- import OneSignal from 'react-native-onesignal';
- import * as notificationsActions from '@modules/notifications/NotificationsState';
- import {NavigationActions} from 'react-navigation';
- setConfiguration('clientID', '169D63FB430EA6782110AD15C4647E5E246323AB5C07611B9997A573C768BFE7');
- console.disableYellowBox = true;
- Colors.loadColors({
- verde: '#1ABC9C',
- verdeLight: '#D9FFF7',
- verdeDark: '#16A085',
- vermelho: '#701E00',
- cinza: '#A6ABAB',
- });
- class VerdeCidadao extends Component {
- constructor() {
- super();
- this.onReceived = this.onReceived.bind(this);
- this.onOpened = this.onOpened.bind(this);
- this.onIds = this.onIds.bind(this);
- // this.onEmailRegistrationChange = this.onEmailRegistrationChange.bind(this);
- }
- async componentDidMount() {
- OneSignal.addEventListener('received', this.onReceived);
- OneSignal.addEventListener('opened', this.onOpened);
- OneSignal.addEventListener('ids', this.onIds);
- }
- componentWillUnmount() {
- OneSignal.removeEventListener('received', this.onReceived);
- OneSignal.removeEventListener('opened', this.onOpened);
- OneSignal.removeEventListener('ids', this.onIds);
- }
- componentWillMount() {
- OneSignal.init('c4d77f04-82dd-4b35-b1a0-6520f4f34bf6');
- OneSignal.setRequiresUserPrivacyConsent(false);
- OneSignal.provideUserConsent(true);
- OneSignal.setLogLevel(6, 0);
- OneSignal.setLocationShared(true);
- OneSignal.inFocusDisplaying(2);
- OneSignal.setSubscription(true);
- }
- onReceived(notification) {
- const id = notification.payload.notificationID;
- store.dispatch(notificationsActions.onReceivedNotifications(id));
- }
- onOpened(openResult) {
- const id = openResult.notification.payload.notificationID;
- store.dispatch(NavigationActions.navigate({routeName: 'MainMenu'}));
- store.dispatch(notificationsActions.detailsNotifications(id, 1));
- }
- onIds(device) {
- console.log('ON IDS');
- this.registerDeviceOneSignal();
- // OneSignal.getPermissionSubscriptionState(status => {
- // console.log(status);
- // });
- }
- registerDeviceOneSignal() {
- const {id, subscribed} = store
- .getState()
- .get('auth')
- .toJS().user;
- OneSignal.setSubscription(true);
- if (id) {
- OneSignal.setExternalUserId(id);
- OneSignal.sendTags({cidadaoId: id});
- }
- }
- render() {
- return (
- <Provider store={store}>
- <AppViewContainer />
- </Provider>
- );
- }
- }
- AppRegistry.registerComponent('VerdeCidadao', () => VerdeCidadao);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement