在我的应用程序中,我使用服务工作者,向第三方API发送请求,并以对象的形式获取响应。如何在服务人员的帮助下保存此数据并将其显示为推送通知?
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open('static')
.then((cache) => {
console.log('These pages have been cached');
return cache.addAll([
'/index.html'
])
})
)
});
self.addEventListener('activate', (event) => {
console.log('Service worker has been activated');
});
self.addEventListener('fetch', (event) => {
console.log('Request has been sent');
});
self.addEventListener('push', event => {
const data = event.data.json();
console.log('Push Received');
self.registration.showNotification(data.title,
{
body: 'Notified Media',
icon: 'https://i.ibb.co/0QBqymX/download.png'
})
});