To get notifications you simply press the subscribe button and you will get prompted with YES/NO to turn on notifications.
If you want to “reset” the prompting for notifications, press the SSL lock, to the left side of the address bar (at least using Brave on desktop).
If you want to send a message to all subscribers you simply press the send message button.
I have tested the notifications on MacOS using the latest version of Safari, Brave and Google Chrome.
On mobile i have only tested on an iphone 8 and IOS 16.4 using safari. In safari it is important that the website is added to Homescreen.
If you don’t get any notifications on your IOS device you might check out this link https://www.xda-developers.com/how-enable-safari-notifications-iphone/. Since Apple recently released this feature on IOS.
This is great - we should think about adding it to anvil-labs service worker implementation.
One anvil.js coding point is that you don’t need to do anvil.js.await_promise in your example.
Specifically places where you access a Promise stored as a property on an object
e.g. this browser api for animation.
Where you access the finished property which is a Promise.
We use await_promise in the anvil_extras animation module to use this api.
Other note - be careful with your uninstall method
It looks like you’re uninstalling all service worker registrations
This includes the default registration from anvil which handles offline capabilities
the following might be better
registrations = self.navigator.serviceWorker.getRegistrations()
for reg in registrations:
I’m keen to copy this and try some variations, I want to send pushes to individuals rather than all, and don’t think I should be using your API key. Just in case I do something that upsets the provider - I don’t expect to but stuff happens.
I have opened the app on Chrome on MacOS and allowed notifications, however I did not get the notification on my Mac after pressing “Send Notification” from a different device.
On Android I subscribed and got a browser notification even without installing the PWA.
I know iOS is very restrictive to PWAs and I think still it is necessary to add to Home Screen to get notifications?
However is it also necessary to install the app as a PWA in MacOS to get the notifications?