-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
58 lines (54 loc) · 1.83 KB
/
App.tsx
File metadata and controls
58 lines (54 loc) · 1.83 KB
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
import { Providers } from './src/components/Providers';
import React, { useEffect, useRef, useState, useCallback } from 'react'
import * as Notifications from 'expo-notifications'
import * as Permissions from 'expo-permissions'
import { Platform } from 'react-native';
import { setUpFetchInBackground } from './src/components/newdirection/Notification/BackgroundTask';
import { prepareSettings, preferencesGetState } from './src/components/Preferences';
import { prepareLanguage } from './src/components/Language';
import I18n from 'i18n-js';
type AppProps = {}
export const App: React.FC<AppProps> = ({ }) => {
useEffect(() => {
const asyncUseEffect = async () => {
registerForNotificationsAsync()
setUpFetchInBackground()
console.log("Setting Notification Handler")
Notifications.setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldPlaySound: true,
shouldSetBadge: true,
}),
});
}
asyncUseEffect()
}, [])
return (
<Providers />
)
};
async function registerForNotificationsAsync() {
// let token;
const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
let finalStatus = existingStatus;
if (existingStatus !== 'granted') {
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
finalStatus = status;
}
if (finalStatus !== 'granted') {
alert(I18n.t("appNotiNotEnabled"));
return;
}
// token = (await Notifications.getExpoPushTokenAsync()).data;
if (Platform.OS === 'android') {
Notifications.setNotificationChannelAsync('default', {
name: 'default',
importance: Notifications.AndroidImportance.MAX,
vibrationPattern: [0, 250, 250, 250],
lightColor: '#FF231F7C',
});
}
// return token;
}
export default App;