web-push-libs / webpush-java

Web Push library for Java
MIT License
318 stars 112 forks source link

Why don't you set public and private key after creating the pushService? #164

Open AhmadAlhajKarim opened 3 years ago

AhmadAlhajKarim commented 3 years ago

pushService.setPrivateKey(privateKey); pushService.setPublicKey(publicKey); This made my code working Also don't forget to convert the payload to json string

martijndwars commented 3 years ago

Thanks for the feedback! Just to see if I understand you correctly; are you saying the documentation/example is unclear/misses these calls? If yes, can you point me to the documentation (wiki/readme)?

AhmadAlhajKarim commented 3 years ago

Yes, in the documentation of the usage example is not been mentioned where to use the private and the public key. Missing calls is after initializing the pushService. //Instantiate the push service, no need to use an API key for Push API pushService = new PushService(); //set the pivate and the public key pushService.setPrivateKey(privateKey); pushService.setPublicKey(publicKey); // Send the notification pushService.send(notification);

Thank you!

newk5 commented 2 years ago

Thank you, I was having the same issues and the documentation misslead me too.

I noticed on the java side those calls were missing just like you said, but on the client side it's missing the public key too! This javascript code:

serviceWorkerRegistration.pushManager.subscribe({userVisibleOnly: true})

Should be:

serviceWorkerRegistration.pushManager.subscribe({userVisibleOnly: true,  applicationServerKey: '<publicKey here>'})