-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
56 lines (49 loc) · 1.3 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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React, {useEffect} from 'react';
import Bar from './src/components/status-bar';
import Navigation from './src/navigations';
import {SafeAreaProvider} from 'react-native-safe-area-context';
import Orientation from 'react-native-orientation';
import AsyncStorage from '@react-native-community/async-storage';
import messaging from '@react-native-firebase/messaging';
const App = () => {
useEffect(() => {
Orientation.unlockAllOrientations();
Orientation.lockToPortrait();
registerAppWithFCM();
requestUserPermission();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const requestUserPermission = async () => {
const enabled = await messaging().requestPermission();
if (enabled) {
getToken();
}
};
const registerAppWithFCM = async () => {
await messaging().registerDeviceForRemoteMessages();
};
const getToken = () => {
messaging()
.getToken()
.then(token => {
console.log('Device Token', token);
AsyncStorage.setItem('deviceToken', token);
});
};
return (
<>
<Bar />
<SafeAreaProvider>
<Navigation />
</SafeAreaProvider>
</>
);
};
export default App;