-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFCMSetup.js
72 lines (64 loc) · 2.46 KB
/
FCMSetup.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
import {useEffect} from 'react';
import {Platform} from 'react-native';
import RNCallKeep from 'react-native-callkeep';
// import messaging from '@react-native-firebase/messaging';
// import {requestNotifications} from 'react-native-permissions';
export const FCMSetup = ({children}) => {
// This effect handles Firebase Cloud Messaging & RNCallKeep permissions
useEffect(() => {
async function requestUserPermission() {
// // Handle permission on IOS
// if (Platform.OS === 'ios') {
// const authStatus = await messaging().requestPermission();
// const enabled =
// authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
// authStatus === messaging.AuthorizationStatus.PROVISIONAL;
// console.log(
// `Authorization status = ${authStatus} ; Is Enabled? = ${enabled}`,
// );
// }
// // Handle permission on Android
// else if (Platform.OS === 'android') {
// const result = await requestNotifications([]);
// console.log('Authorization status:', result);
// }
// Handle Callkeep setup and permissions
RNCallKeep.setup({
android: {
alertTitle: 'Permissions required',
alertDescription:
'This application needs to access your phone accounts',
cancelButton: 'Cancel',
okButton: 'ok',
imageName: 'phone_account_icon',
// additionalPermissions: [PermissionsAndroid.PERMISSIONS.example],
additionalPermissions: [],
// Required to get audio in background when using Android 11
foregroundService: {
channelId: 'com.company.my',
channelName: 'Foreground service for my app',
notificationTitle: 'My app is running on background',
// notificationIcon: 'Path to the resource icon of the notification',
},
},
});
}
requestUserPermission();
}, []);
// Registers FCM forground listener
// useEffect(() => {
// // Get FCM Token
// messaging()
// .getToken()
// .then(token => console.log('FCM Token -> ', token));
// // Register subscription to handle FCM Message in Foreground state
// const unsubscribe = messaging().onMessage(async remoteMessage => {
// console.log(
// 'FCM Message handled in Foreground -> ',
// JSON.stringify(remoteMessage, null, 2),
// );
// });
// return unsubscribe;
// }, []);
return children;
};