Show Menu
Cheatography

Push Notifications Cheat Sheet by

Cheatsheet for NVS

First Steps

Links

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('s­w.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­ener('‐ 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!
       
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Dojo 1.8 Cheat Sheet
          IoT Intro Cheat Sheet
          HTML Cheatsheet Cheat Sheet

          More Cheat Sheets by bausac16

          Single-Area OSPF Cheat Sheet
          Mobile Application Cheat Sheet