-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (56 loc) · 1.52 KB
/
index.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
import * as Permissions from '../../node_modules/expo/src/Permissions.js';
import Notifications from '../../node_modules/expo/src/Notifications.js';
import { configConsole } from '../../config';
import { AsyncStorage } from '../../node_modules/react-native/Libraries/react-native/react-native-implementation.js';
/*
{
to: // exp token
data:{
action: // [route, dialog, ]
route_name: // routeName of ReactNavigation
params:
title:
message:
}
title:
body:
sound:
param:
ttl:
expiration:
priority:
badge:
} */
const EsoftplayNotification = {
listen(callback) {
Notifications.addListener((obj) => {
if (obj) {
if (callback) callback(obj)
if (obj.remote) {
AsyncStorage.setItem('esoftplaynotification', JSON.stringify(obj))
}
}
})
},
get(action) {
setTimeout(() => {
AsyncStorage.getItem('esoftplaynotification').then((res) => {
res = JSON.parse(res)
action(res)
AsyncStorage.removeItem('esoftplaynotification')
}, 1500);
})
},
async requestPermission(token) {
const { existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
let finalStatus = existingStatus;
if (existingStatus !== 'granted') {
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
finalStatus = status;
}
if (finalStatus !== 'granted') return
configConsole(finalStatus)
token(await Notifications.getExpoPushTokenAsync())
}
}
export default EsoftplayNotification