Sending Web Push to PWA/Safari iOS from java server

In this tutorial, you demonstrate subscribing for receive web push notifications in your desktop browser.

https://hilla.dev/blog/send-web-push-notifications-java/

Have you been able to also get this working on a mobile PWA on iOS/Safari ? I have struggled to get this working. I do have it working with Android/Chrome. When I send the notification to a https://web.push.apple.com/… endpoint, I’m getting the following response:

Response: statusline:HTTP/1.1 403 Forbidden
header:content-type=text/plain; charset=UTF-8
header:content-length=24
header:apns-id=C3C08124-25E0-754F-B1BF-C01435907957
protocol version:HTTP/1.1
entity:[Content-Length: 24,Chunked: false]

This is bit out of Vaadin/Hilla subject as problem is in the web-push library, but seems that I found an answer.
https://github.com/web-push-libs/webpush-java/issues/201

At least I made safari to work with adding subject to PushService:
pushService = new PushService(publicKey, privateKey, "mailto:mail@example.com");

Cool. Thanks. I’ll give it a try.

Thank you soooo much, @kriss! That did it. Just adding a mailto as the subject was magic. Its amazing that APNs was returning a 403 Forbidden with no other help diagnosing the issue. Wow! Anyway, I really appreciate your help. I know this wasn’t a vaddin/hilla issue, but you helped out anyway. :slightly_smiling_face:

Glad that it work :smiling_face:
Another thing I suspected was: Encoding.AES128GCM, as by default “AESGCM” is used. As I was testing with: https://simple-push-demo.vercel.app/.
Then I noticed there was a body in the response from PushService.send with “reason BadJwtToken” which helped me to find the gihub issue and then this solution.