-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
72 lines (62 loc) · 1.92 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// App.js
import React, { useEffect, useState, useRef } from "react";
import Toast from 'react-native-toast-message';
import Navigation from "./navigation/Navigation";
import * as Notifications from "expo-notifications";
Notifications.setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldPlaySound: true,
shouldSetBadge: true,
}),
});
export default function App() {
const [expoPushToken, setExpoPushToken] = useState("");
const [notification, setNotification] = useState(false);
const notificationListener = useRef();
const responseListener = useRef();
useEffect(() => {
try {
// registerForPushNotificationsAsync().then(token => setExpoPushToken(token));
notificationListener.current =
Notifications.addNotificationReceivedListener((notification) => {
setNotification(notification);
});
responseListener.current =
Notifications.addNotificationResponseReceivedListener((response) => {
console.log(response);
});
} catch (error) {}
(async () => scheduleDailyNotifications())();
return () => {
Notifications.removeNotificationSubscription(
notificationListener.current
);
Notifications.removeNotificationSubscription(responseListener.current);
};
}, []);
return(
<>
<Navigation />
<Toast />
</>
);
}
async function scheduleDailyNotifications() {
// Schedule the notification at 11 am
await Notifications.scheduleNotificationAsync({
content: {
title: "Good Morning!",
body: "It's time to update your menu..!",
},
trigger: { hour: 11, minute: 0, repeats: true },
});
// Schedule the notification at 6:30 pm
await Notifications.scheduleNotificationAsync({
content: {
title: "Good Evening!",
body: "Don't forget to update the menu..!",
},
trigger: { hour: 18, minute: 30, repeats: true },
});
}