-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
89 lines (79 loc) · 2.53 KB
/
App.tsx
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import {NavigationContainer} from '@react-navigation/native';
import React, {useEffect} from 'react';
// import {Alert} from 'react-native';
import RootStack from './src/screens/RootStack';
import {QueryClient, QueryClientProvider} from 'react-query';
import {Provider} from 'react-redux';
import store from './src/slices';
import {
request,
PERMISSIONS,
// requestMultiple,
// requestNotifications,
} from 'react-native-permissions';
import {AppState, Platform} from 'react-native';
import messaging from '@react-native-firebase/messaging';
const queryClient = new QueryClient();
async function requestUserPermission() {
const authorizationStatus = await messaging().requestPermission();
if (authorizationStatus) {
console.log('Permission status:', authorizationStatus);
}
}
requestUserPermission();
// requestMultiple([PERMISSIONS.IOS.CAMERA, PERMISSIONS.IOS.FACE_ID]).then(
// statuses => {
// console.log('Camera', statuses[PERMISSIONS.IOS.CAMERA]);
// console.log('FaceID', statuses[PERMISSIONS.IOS.FACE_ID]);
// },
// );
function App() {
useEffect(() => {
messaging().onNotificationOpenedApp(remoteMessage => {
console.log(
'Notification caused app to open from background state:',
remoteMessage.notification,
);
});
messaging()
.getInitialNotification()
.then(remoteMessage => {
if (remoteMessage) {
console.log(
'Notification caused app to open from quit state:',
remoteMessage.notification,
);
}
});
const unsubscribe = messaging().onMessage(async remoteMessage => {
// Alert.alert(
// 'A new FCM message arrived!',
// JSON.stringify(remoteMessage.notification),
// );
//이 부분이 어플 실행중 알림을 받는 부분 -> 스타일 수정 필요
console.log(JSON.stringify(remoteMessage));
console.log(remoteMessage);
});
return unsubscribe;
}, []);
useEffect(() => {
const listener = AppState.addEventListener('change', status => {
if (Platform.OS === 'ios' && status === 'active') {
request(PERMISSIONS.IOS.APP_TRACKING_TRANSPARENCY)
.then(result => console.log(result))
.catch(error => console.log(error));
}
});
return listener.remove;
}, []);
return (
<QueryClientProvider client={queryClient}>
<Provider store={store}>
<NavigationContainer>
<RootStack />
</NavigationContainer>
</Provider>
</QueryClientProvider>
);
}
export default App;