-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnotify.js
More file actions
51 lines (43 loc) · 1.31 KB
/
notify.js
File metadata and controls
51 lines (43 loc) · 1.31 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
const { Expo } = require('expo-server-sdk');
function sendNotifiaction(somePushTokens, notice){
let expo = new Expo();
let messages = [];
for (let pushToken of somePushTokens) {
// Each push token looks like ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]
// Check that all your push tokens appear to be valid Expo push tokens
if (!Expo.isExpoPushToken(pushToken)) {
console.error(`Push token ${pushToken} is not a valid Expo push token`);
continue;
}
// Construct a message (see https://docs.expo.io/versions/latest/guides/push-notifications.html)
messages.push({
to: pushToken,
title: notice.title,
sound: 'default',
body: notice.body,
// data: { withSome: 'data' },
})
}
let chunks = expo.chunkPushNotifications(messages);
let tickets = [];
(async () => {
for (let chunk of chunks) {
try {
let ticketChunk = await expo.sendPushNotificationsAsync(chunk);
console.log(ticketChunk);
tickets.push(...ticketChunk);
} catch (error) {
console.error(error);
}
}
})();
}
// var notice ={
// title : "hello",
// body : "test is add"
// }
// var somePushTokens = ['ExponentPushToken[EsHe2EGgQAJPHE7CnmfKyk]']
// sendNotifiaction(somePushTokens, notice);
module.exports = {
sendNotifiaction
};