Answer the question
In order to leave comments, you need to log in
How to properly create a function to receive notifications?
The question probably has no solution in principle with this approach, but I'll try.
I have an array with signals:
[
{
"idSite": 123456,
"type": "1",
"description": "SIGNAL 1",
"dateTime": "2019-04-20 00:00:00"
},
{
"idSite": 123456,
"type": "2",
"description": "SIGNAL 2",
"dateTime": "2019-04-20 00:00:00"
},
{
"idSite": 123455,
"type": "4",
"description": "SIGNAL 3",
"dateTime": "2019-04-20 00:00:00"
}
]
if (dataObject !== null) {
let token = await Notifications.getExpoPushTokenAsync();
console.log(token)
let response = await fetch('https://exp.host/--/api/v2/push/send', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
to: token,
title: dataObject[0].description,
sound: 'default',
body: dataObject[0].dateTime
})
})
}
Answer the question
In order to leave comments, you need to log in
I'm not sure, because "How to correctly create a function for receiving notifications", but I'll try) The Push Notifications
documentation has
// пакетная
[{
"to": "ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]",
"sound": "default",
"body": "Hello world!"
}, {
"to": "ExponentPushToken[yyyyyyyyyyyyyyyyyyyyyy]",
"badge": 1,
"body": "You've got mail"
}]
// обычная
{
"to": "ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]",
"title":"hello",
"body": "world"
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question