I am using service worker concept (API) to send web push notifications, this is the book that I followed and got the code sample from. Below code works perfectly fine to get the subscription from a client and I am able to send notifications successfully on Chrome android devices
navigator.serviceWorker.register('sw.js').then(function (registration){
return registration.pushManager.getSubscription().then(function (subscription){
})
}).catch()
...
The exact code doesn't seem to work on iPhone chrome web browser. I tried to add some console.logs to see what's happening and it looks like the registration object that we got from above code doesn't have pushManager property set and because of that below is the problem that I see in iPhone chrome console logs.
TypeError: undefined is not an object (evaluating 'registration.pushManager.getsubscription')
Here is the code that adds those console logs
navigator.serviceWorker.register('sw.js').then(function (registration){
if (registration){
console.log("registration is found " , registration)
} else {
console.log("registration is not found")
}
if (registration.pushManager){
console.log("pushmanager was found on registration and calling getSubscription() ", registration.pushManager.getSubscription())
} else{
console.log("pushmanager was not found on registration")
}
...
...
and the output of this code, on iPhone chrome browser is attached here.
I was wondering if I should Notification API instead, but was not able to figure out if I can get subscription details using Notification API.
I wanted to see if someone already got into this problem and was able to resolve that.
The other thing that I was able to figure out was
'PushManager' in window
returns false in the envs where notifications are not working (iOS chrome).
