i have a pwa created with angular 9
, the application is for trading, so data, changes
almost every second , my users can create statements and when their statements become
true my application will notice them by sending notification , i also have a service
worker installed and activated , everything is good in desktop and also in mobile
but when mobile screen turns off or pwa minimized , pwa stop working and notifications
are not send anymore , i tried background-sync
and periodic-background-sync
, but wasnt
helpful
can anyone give me a clue what i have to do ?
this is my serviceWorker
async function grantPeriodic(){
const status = await navigator.permissions.query({
name: 'periodic-background-sync',
});
if (status.state === 'granted') {
console.log("granted");
} else {
}
}
async function periodicSyncFunc(){
const registration = await navigator.serviceWorker.ready;
if ('periodicSync' in registration) {
try {
console.log("synced");
await registration.periodicSync.register('content-sync', {
minInterval: 10000,
});
} catch (error) {
}
}
}
self.addEventListener('periodicsync', (event) => {
if (event.tag === 'content-sync') {
event.waitUntil(
periodicSyncFunc()
);
}
});
grantPeriodic() ;