Push Notifications Cheat Sheet

A cheat sheet in English by bausac16

Cheatsheet for NVS

9,361 views 1,638 downloads 21 Jan 2020 History
3.7 avg · 0 ratings

Supple­mentary Features

Notifi­cation Click
sw.js
event.n­ot­ifica‐ tion.c­lose();
Notifi­cation Click
sw.js
client­s.o­penWi‐ ndow('htt‐ ps://d­evelop‐ ers.go­ogle.c‐ om/web­/')
Unsubs­cribe
main.js
subscr­ipt­ion.u‐ nsubsc­ribe(); & update­Sub­scrip‐ tionOn­Server‐ (null);
sw.js and main.js are included in the setup folder!

Activate Push Notifi­cation

Public Private Key
Copy paste the subscr­iption
located on bottom of the page

Basic changes from the original

Service Worker
sw.js
naviga­tor.serv‐ iceWor­ker.regis‐ ter('sw.js­')
Attach key
main.js
const applicati‐ onServ­erPubl‐ icKey = '­<Your Public Key>';
update­-Btn()
main.js
enables / disables button depending on subscr­iption of user | call in initia­liz­eUI()
Click Listener
initia­liz­eUI()
pushBu­tto­n.add‐ EventL­ist­ene­r('‐ click', function() {...}
subscr­ibe­User()
main.js
swRegi­strat‐ ion.pu­shMana‐ ger.su­bsc­ribe({ userVi­sib­leOnly: true, applicati‐ onServ­erKey: applic­ati­onServ‐ erKey }) .then(‐ functi­on(­subscr‐ iption) {...})
update­OnS­erver()
main.js
Sends subscr­iption to the backend
Handle Push Event
sw.js
listens for the event and shows a notifi‐ cation (conso­le.log)
sw.js and main.js are included in the setup folder!

Badges

Nice Cheat Sheet

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.