-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
97 lines (83 loc) · 2.96 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
90
91
92
93
94
95
96
97
import dynamicLinks, { FirebaseDynamicLinksTypes } from '@react-native-firebase/dynamic-links';
import messaging from '@react-native-firebase/messaging';
import { LinkingOptions, NavigationContainer } from '@react-navigation/native';
import { observer } from 'mobx-react';
import React, { useEffect } from 'react';
import { Linking } from 'react-native';
import MainNavigator from '~/navigations/MainNavigator';
const config = {
screens: {
Intro: 'intro',
Home: 'home',
TemplateList: 'TemplateList',
EditTask: 'EditTask',
InviteIntro: 'InviteIntro',
},
};
const linking: LinkingOptions = {
prefixes: ['bonkae-master://', 'https://bonkae.page.link', 'http://bonkae.page.link'],
async getInitialURL(): Promise<string | null> {
const url = await Linking.getInitialURL();
const dynamicLinkUrl = await dynamicLinks().getInitialLink();
if (dynamicLinkUrl) {
const links = dynamicLinkUrl.url.split('/');
const deepLink = links[links.length - 2];
const taskId = links[links.length - 1];
if (deepLink === 'tasks') {
return `bonkae-master://InviteIntro?taskId=${taskId}`;
}
}
if (url) {
const links = url.split('?');
const taskIdObject = links[links.length - 1].split('=');
const taskId = taskIdObject[taskIdObject.length - 1];
return `bonkae-master://InviteIntro?taskId=${taskId}`;
}
return null;
},
subscribe(listener: (deeplink: string) => void) {
const onReceiveURL = ({ url }: { url: string }) => listener(url);
Linking.addEventListener('url', onReceiveURL);
const handleDynamicLink = (dynamicLink: FirebaseDynamicLinksTypes.DynamicLink) => {
listener(dynamicLink.url);
};
const unsubscribeToDynamicLinks = dynamicLinks().onLink(handleDynamicLink);
return () => {
unsubscribeToDynamicLinks();
Linking.removeEventListener('url', onReceiveURL);
};
},
config: config,
};
const App = observer(() => {
// 아이폰 권한 허용 관련
useEffect(() => {
const requestUserPermission = async () => {
const authStatus = await messaging().requestPermission();
const enabled =
authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
authStatus === messaging.AuthorizationStatus.PROVISIONAL;
if (enabled) {
console.log('Authorization status:', authStatus);
}
};
requestUserPermission();
}, []);
// 백그라운드 상태일 때 푸시 알림
messaging().setBackgroundMessageHandler(async (remoteMessage) => {
console.log('Message handled in the background!', remoteMessage);
});
// 앱 접속 중인 상태일 때 푸시 알림
useEffect(() => {
const unsubscribe = messaging().onMessage(async (remoteMessage) => {
console.log('A new FCM message arrived!', JSON.stringify(remoteMessage));
});
return unsubscribe;
}, []);
return (
<NavigationContainer linking={linking}>
<MainNavigator />
</NavigationContainer>
);
});
export default App;