Apple Devices (iPhone and iPad) cant receive the webpush notification
Hi, i'm trying to send webpush notification to all my devices (android, ios, and windows). its working for the android and windows devices, but not for ios. Any solution? Thanks!
Oh ya, i have already tried to use another webpush library using javascript and python, and its perfectly working for ios.
Could you share the code you are using? I'm using the library without any issues
I am also facing same issue, i do not get web push notification in IOS devices. One more thing how can i send web push notification to the user who is logged to multiple device or browser
web push working with iOS Safari (w/PWA),only need VAPID? Is APNs certificate required?
I ran into the same issue—chances are you're seeing a BadJwtToken error because you're using a mailto:
According to Apple's documentation, the sub must be either a valid mailto: or URL. However, in practice, using mailto: seems to trigger the error, while a URL works as expected.
Adding my two cents here, I had the same issue and indeed using an HTTPS URL as the Subscriber solved it.
Unfortunately the error returned by SendNotification is nil, ~but I'm not sure if it's a lib error not propagating the BadJwtToken error or if it's the Apple endpoint returning a status 201 and thus silently failing~.
Edit: Just noticed that the returned error by SendNotification is directly the http.Response so it is indeed Apple returning 201 even for invalid requests.
Having the same issue here, even with an HTTPS URL as the Subscriber. Is there any way to get back a better response message from the APNs?
I was able to fix. For anyone else in the same boat, my problem was using the vite-pwa plugin in Sveltekit. The plugin was generating a service worker file with the same name as my notification handling service worker, so it would get overwritten. There was some cache issues in there too which is why it worked on other browsers momentarily.
🤦
I ran into the same issue—chances are you're seeing a BadJwtToken error because you're using a mailto: in the sub (subject) claim. I switched it to a URL instead (e.g., https://example.com) and it worked.
According to Apple's documentation, the sub must be either a valid mailto: or URL. However, in practice, using mailto: seems to trigger the error, while a URL works as expected.
This is actually unnecessary. The issue is that this library already adds the "mailto:" so if you're passing "mailto:[email protected]" then the library turn it into "mailto:mailto:[email protected]". The solution is to ONLY pass the email without the "mailto:"
Code in question: https://github.com/SherClockHolmes/webpush-go/blob/f5c3e9f7b642a8dd66cb844050520526f721971d/vapid.go#L77
@hafidzyami please mark as closed
Adding more context to someone who just yesterday got a similar issue, but managed to make it work, here's a couple things about my scenario and what was done to make it work:
- Ensure your server providing the
index.htmland yourservice-worker.jsis running with SSL (you can't use service workers outside localhost without SSL) - Ensure that your page in iOS is added to your home screen. That's the only way Apple allows PWA methods to be used
- Apple prevents push registrations to be triggered on load, so you must wrap the registration to a method and set it to a button click to allow it.
Then, some more details on the environment and my steps to understand the issue:
- Set up VAPID keys on your Go application
- Ran the example code through
python -m http.server 8000 - Opened localhost:8000 on my browser and worked just fine
- Went to my phone and tried to access my computer's http server; no results
At this point, we get the first issue debugging: there's no serviceWorker available if you don't have SSL and tries to access a non-HTTPS server, so the basic test server ends its testing power here.
There's a 10-line python code that given a cert and a key, you can spin up a simple https server (I can pull request later to the example folder), which allows you to run the example server with a self-signed https certificate.
Then at this point, we get the second issue debugging: Apple only implements pushNotification on ServiceWorkerRegistration class if your PWA is set as an app (press the "…" > "Share" > "Add to Home Screen").
Finally, the last issue: Apple does not allow the application to auto-trigger the request for push notifications, so you'll need to wrap the whole if ('serviceWorker' in navigator) { /* ... */ } block into a function, add a button that then triggers this function.