forked from evollu/react-native-fcm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
52 lines (38 loc) · 1.09 KB
/
index.js
File metadata and controls
52 lines (38 loc) · 1.09 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
import {NativeModules, DeviceEventEmitter} from 'react-native';
const eventsMap = {
refreshToken: 'FCMTokenRefreshed',
notification: 'FCMNotificationReceived'
};
const FIRMessaging = NativeModules.RNFIRMessaging;
const FCM = {};
FCM.getFCMToken = () => {
if (!FIRMessaging) return;
return FIRMessaging.getFCMToken();
};
FCM.requestPermissions = () => {
if (!FIRMessaging) return;
return FIRMessaging.requestPermissions();
};
FCM.on = (event, callback) => {
const nativeEvent = eventsMap[event];
const listener = DeviceEventEmitter.addListener(nativeEvent, callback);
return function remove() {
listener.remove();
};
};
FCM.subscribeToTopic = (topic) => {
if (!FIRMessaging) return;
FIRMessaging.subscribeToTopic(topic);
};
FCM.unsubscribeFromTopic = (topic) => {
if (!FIRMessaging) return;
FIRMessaging.unsubscribeFromTopic(topic);
};
//once doesn't seem to work
DeviceEventEmitter.addListener('FCMInitData', (data)=>{
FCM.initialData = data;
});
if (FIRMessaging){
FCM.initialData = FIRMessaging.initialData;
}
module.exports = FCM;