-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
49 lines (42 loc) · 1.29 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
import React, {useEffect} from 'react';
import {View, Button} from 'react-native';
import {fcmServices} from './src/fcmServices';
import {localNotificationServices} from './src/localNotificationSercives';
const App = () => {
useEffect(() => {
fcmServices.registerAppWithFCM();
fcmServices.register(onRegister, onNotification, onOpenNotification);
localNotificationServices.configure(onOpenNotification);
function onRegister(token) {
console.log('[App], onRegister: ', token);
}
function onNotification(notify) {
console.log('[App], onNotification: ', notify);
const options = {
playSound: true,
};
localNotificationServices.showNotification(
0,
notify.title,
notify.body,
notify,
options,
);
}
return () => {
console.log('[App], unRegistered');
fcmServices.unRegister();
localNotificationServices.unRegister();
};
}, []);
function onOpenNotification(notify) {
console.log('[App], onOpenNotification: ', notify);
alert('Open Notification: ' + notify.body);
}
return (
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
<Button title="Press me" onPress={() => console.log('Hello')} />
</View>
);
};
export default App;