admin管理员组文章数量:1025322
- I have a React application using NextJS, deployed on Vercel.
- I want to use OneSignal to send notifications
I have a certain feature in my app called "Reminders", which is just a MySQL table using the Prisma ORM. Here is the table schema:
model Tasks {
id Int @id @default(autoincrement())
name String
note String?
frequency String
on String
lastDone DateTime
property Property? @relation(fields: [propertyId], references: [id])
propertyId String?
}
- I have already set up an API endpoint called
/api/property/tasks
(POST) which returns the current task list- The API requires a token in the body, which is stored via a cookie called
sessionToken
(which never expires) - A variable called
nextDue
is already calculated based on thefrequency
andon
values. (This returns anew Date()
)
- The API requires a token in the body, which is stored via a cookie called
- Using Service Workers and the OneSignal API, how do I make my app send notifications to the user's device when the device's time is equal to
nextDate
, even if the browser tab is closed? - The service worker will need to update to the new data to send the correct push notification in case the task gets deleted or the date gets updated
Thank you!
EDIT: I'm OK with a solution without using the OneSignal API preferably.
- I have a React application using NextJS, deployed on Vercel.
- I want to use OneSignal to send notifications
I have a certain feature in my app called "Reminders", which is just a MySQL table using the Prisma ORM. Here is the table schema:
model Tasks {
id Int @id @default(autoincrement())
name String
note String?
frequency String
on String
lastDone DateTime
property Property? @relation(fields: [propertyId], references: [id])
propertyId String?
}
- I have already set up an API endpoint called
/api/property/tasks
(POST) which returns the current task list- The API requires a token in the body, which is stored via a cookie called
sessionToken
(which never expires) - A variable called
nextDue
is already calculated based on thefrequency
andon
values. (This returns anew Date()
)
- The API requires a token in the body, which is stored via a cookie called
- Using Service Workers and the OneSignal API, how do I make my app send notifications to the user's device when the device's time is equal to
nextDate
, even if the browser tab is closed? - The service worker will need to update to the new data to send the correct push notification in case the task gets deleted or the date gets updated
Thank you!
EDIT: I'm OK with a solution without using the OneSignal API preferably.
Share Improve this question edited Oct 9, 2022 at 19:46 Manu G asked Oct 7, 2022 at 2:19 Manu GManu G 1735 silver badges14 bronze badges 2- You can try this dev.to/onesignal/… – Divyessh Commented Oct 10, 2022 at 19:09
- Hi! Thank you for your ment, however, the article you sent does not explain how to send push notifications directly from the app itself. My app needs to send push notifications automatically at a given time to users – Manu G Commented Oct 11, 2022 at 17:21
2 Answers
Reset to default 4 +50I guess you are looking for two capabilities of service workers (learn about all available capabilities here):
- Periodic Background Sync API
- Notifications API
You can follow these two reference guides by Microsoft:
- Use the Periodic Background Sync API to regularly get fresh content
- Display notifications in the action center
Do not confuse yourself between Push API & Notifications API. You are only looking for notification functionality not push.
I know this is late but for anyone in the future I have a working example here. it uses the web-push library along with next-pwa.
code: https://github./david-randoll/push-notification-nextjs
live demo: https://push-notification.davidrandoll./
One iPhones, you need to Add to Home first b4 it works.
- I have a React application using NextJS, deployed on Vercel.
- I want to use OneSignal to send notifications
I have a certain feature in my app called "Reminders", which is just a MySQL table using the Prisma ORM. Here is the table schema:
model Tasks {
id Int @id @default(autoincrement())
name String
note String?
frequency String
on String
lastDone DateTime
property Property? @relation(fields: [propertyId], references: [id])
propertyId String?
}
- I have already set up an API endpoint called
/api/property/tasks
(POST) which returns the current task list- The API requires a token in the body, which is stored via a cookie called
sessionToken
(which never expires) - A variable called
nextDue
is already calculated based on thefrequency
andon
values. (This returns anew Date()
)
- The API requires a token in the body, which is stored via a cookie called
- Using Service Workers and the OneSignal API, how do I make my app send notifications to the user's device when the device's time is equal to
nextDate
, even if the browser tab is closed? - The service worker will need to update to the new data to send the correct push notification in case the task gets deleted or the date gets updated
Thank you!
EDIT: I'm OK with a solution without using the OneSignal API preferably.
- I have a React application using NextJS, deployed on Vercel.
- I want to use OneSignal to send notifications
I have a certain feature in my app called "Reminders", which is just a MySQL table using the Prisma ORM. Here is the table schema:
model Tasks {
id Int @id @default(autoincrement())
name String
note String?
frequency String
on String
lastDone DateTime
property Property? @relation(fields: [propertyId], references: [id])
propertyId String?
}
- I have already set up an API endpoint called
/api/property/tasks
(POST) which returns the current task list- The API requires a token in the body, which is stored via a cookie called
sessionToken
(which never expires) - A variable called
nextDue
is already calculated based on thefrequency
andon
values. (This returns anew Date()
)
- The API requires a token in the body, which is stored via a cookie called
- Using Service Workers and the OneSignal API, how do I make my app send notifications to the user's device when the device's time is equal to
nextDate
, even if the browser tab is closed? - The service worker will need to update to the new data to send the correct push notification in case the task gets deleted or the date gets updated
Thank you!
EDIT: I'm OK with a solution without using the OneSignal API preferably.
Share Improve this question edited Oct 9, 2022 at 19:46 Manu G asked Oct 7, 2022 at 2:19 Manu GManu G 1735 silver badges14 bronze badges 2- You can try this dev.to/onesignal/… – Divyessh Commented Oct 10, 2022 at 19:09
- Hi! Thank you for your ment, however, the article you sent does not explain how to send push notifications directly from the app itself. My app needs to send push notifications automatically at a given time to users – Manu G Commented Oct 11, 2022 at 17:21
2 Answers
Reset to default 4 +50I guess you are looking for two capabilities of service workers (learn about all available capabilities here):
- Periodic Background Sync API
- Notifications API
You can follow these two reference guides by Microsoft:
- Use the Periodic Background Sync API to regularly get fresh content
- Display notifications in the action center
Do not confuse yourself between Push API & Notifications API. You are only looking for notification functionality not push.
I know this is late but for anyone in the future I have a working example here. it uses the web-push library along with next-pwa.
code: https://github./david-randoll/push-notification-nextjs
live demo: https://push-notification.davidrandoll./
One iPhones, you need to Add to Home first b4 it works.
本文标签: javascriptHow do I implement Push notifications to my React application using NextJSStack Overflow
版权声明:本文标题:javascript - How do I implement Push notifications to my React application using NextJS? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745615662a2159275.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论