webpush-java icon indicating copy to clipboard operation
webpush-java copied to clipboard

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

Open AhmadAlhajKarim opened this issue 4 years ago • 3 comments
trafficstars

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

AhmadAlhajKarim avatar Mar 22 '21 17:03 AhmadAlhajKarim

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)?

martijndwars avatar Mar 23 '21 15:03 martijndwars

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!

AhmadAlhajKarim avatar Mar 23 '21 15:03 AhmadAlhajKarim

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>'})

newk5 avatar Dec 15 '21 18:12 newk5