-
Notifications
You must be signed in to change notification settings - Fork 18
/
App.js
74 lines (65 loc) · 1.91 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import React, { PureComponent } from 'react';
import { YellowBox, AsyncStorage } from 'react-native';
import Messaging from '@react-native-firebase/messaging';
import { Provider } from 'react-redux';
import { PersistGate } from 'redux-persist/lib/integration/react';
import { MenuProvider } from 'react-native-popup-menu';
import Countly from 'countly-sdk-react-native';
import Reactotron from 'reactotron-react-native';
import './ReactotronConfig';
import { serverConfig } from './utils/server';
import store, { persistor } from './store';
import OnboardingWrapper from './OnboardingWrapper';
const ignorableWarnings = [
'Can only update a mounted or mounting component.',
'Module RNToastNative requires',
];
YellowBox.ignoreWarnings(ignorableWarnings);
Countly.enableCrashReporting(false);
export default class App extends PureComponent {
constructor(props) {
super(props);
serverConfig.setServerToken(props.server_token);
}
async componentDidMount() {
this.checkPermission();
}
getToken = async () => {
let fcmToken = await AsyncStorage.getItem('fcmToken');
if (!fcmToken) {
fcmToken = await Messaging().getToken();
if (fcmToken) {
// user has a device token
await AsyncStorage.setItem('fcmToken', fcmToken);
}
}
Reactotron.log('------------', fcmToken);
}
checkPermission = async () => {
const enabled = await Messaging().hasPermission();
if (enabled) {
this.getToken();
} else {
this.requestPermission();
}
}
async requestPermission() {
try {
await Messaging().requestPermission();
this.getToken();
} catch (error) {
console.log('permission rejected');
}
}
render() {
return (
<Provider store={store}>
<PersistGate persistor={persistor}>
<MenuProvider>
<OnboardingWrapper />
</MenuProvider>
</PersistGate>
</Provider>
);
}
}