-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
81 lines (70 loc) · 2.15 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
73
74
75
76
77
78
79
80
81
import { useEffect } from 'react';
import Navigation from "./navigation";
import { Platform } from 'react-native';
import * as Notifications from 'expo-notifications';
import { FIREBASE_DB } from './firebaseConfig';
import { doc, onSnapshot } from 'firebase/firestore';
export default function App() {
//// 알림 권한 설정
// useEffect(() => {
// Notifications.getPermissionsAsync()
// .then((status) => {
// if (status.status !== 'granted') {
// return Notifications.requestPermissionsAsync();
// }
// })
// .then((status) => {
// if (status.status !== 'granted') {
// alert('No notification permissions!');
// return;
// }
// });
// }, []);
useEffect(() => {
// 푸시 알림 채널 설정
if (Platform.OS === 'android') {
Notifications.setNotificationChannelAsync('default', {
name: 'default',
importance: Notifications.AndroidImportance.MAX,
vibrationPattern: [0, 250, 250, 250],
lightColor: '#FF231F7C',
});
}
// 물을 5번 줬을 때, 급수통 채워달라고 푸시 알림
onSnapshot(doc(FIREBASE_DB, "farminformation", "push"), (doc) => {
const water = doc.data().water
if (water === 5) {
Notifications.scheduleNotificationAsync({
content: {
title: '식물 관리 시스템 🪴',
body: '💧 급수통의 물을 채워주세요!',
},
trigger: null,
});
}
});
// 시든 잎 감지 되었을 때, 푸시 알림
onSnapshot(doc(FIREBASE_DB, "farminformation", "leaf"), (doc) => {
Notifications.scheduleNotificationAsync({
content: {
title: '식물 관리 시스템 🪴',
body: '📸 시든 잎이 감지되었습니다!',
},
trigger: null,
});
});
// 알림 핸들러 설정
Notifications.setNotificationHandler({
handleNotification: async () => {
return {
shouldShowAlert: true,
shouldPlaySound: true,
shouldSetBadge: false,
};
},
});
},[]);
return (
<Navigation />
);
}