I thought that since I am using local notifications I didn’t need to send notifications to an external server. I guess I need this step. But why has it been working during development even though I never implemented anything in the docs here: https://docs.expo.io/push-notifications/sending-notifications/
After looking at the docs in the link you provided, I managed to implement the push receipt in my code and console.log
a receipt. Now I suppose I could write the response to a log file. But I can’t figure out how to access content
of scheduleNotificationAsync; this content
would be sent in the request for a receipt instead of hardcoding a message in the body of a json request as seen in the link you provided.
I also see there is a handleError
method on the setNotificationHandler
; I was thinking that I could put the push receipts
code there.
This is what I have for push receipts (but not sure how to input the body: JSON.stringify
from my scheduled Notification body:
// first send a push notification with body text
async function getNotifsFromApiAsync() {
return await fetch('https://exp.host/--/api/v2/push/send', {
method: 'POST',
headers: {
Host: 'exp.host',
Accept: 'application/json',
'Accept-Encoding': 'gzip, deflate',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"to": "ExponentPushToken[in3MwyHdqFTopctcsNwBdI]",
"title": "hello from ekad app",
"body": "sent from fetch post"
})
})
.then(response => response.json())
.then(responseJson => {
const ticketIdString = responseJson.data.id;
console.log(ticketIdString)
//this is the post request with the id from the send request above to check for errors
fetch('https://exp.host/--/api/v2/push/getReceipts', {
method: 'POST',
headers: {
Host: 'exp.host',
Accept: 'application/json',
'Accept-Encoding': 'gzip, deflate',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"ids": [ticketIdString]
})
})
.then(response => response.json())
.then(receiptJson => {
console.log('this is receipt json', receiptJson)
})
return;
})
.catch(error => {
console.error(error);
});
}
getNotifsFromApiAsync()