Web Push with Mobile Safari (iOS 16.4) made easy
iOS 16.4 finally supports Push Notifications. Here is how to use them.
Since a few weeks the mobile Safari now supports Push Notifications. Of course I had to try it out and of course it didn't work right away, so here is a short summary of what you need:
- First of all you need VAPID Keys, that's just a keypair you can generate yourself, you don't have to register anywhere, like for push notifications for Apple App Store Apps. I won't link to any of those shady sites where you can do that in a web form. You can do it via OpenSSL.
registers the service worker and handles the registration for push notifications. On iOS, the important thing here
is that the request for permissions happens in an
onclickhandler and not directly when the page is opened
- A backend that stores the endpoints and tokens obtained from the browser.
- The app must be installed on the homescreen and needs a
manifest.json. I used
displayfield in the manifest.
- A backend component to send pushes. For PHP I used the minishlik/web-push library.
Done! If you know how it works, it's quite easy, right?