As the title says, I’m having problems checking web push notifications permissions just on safari. Also note that this does not happens on every single iOS device.
When my app loads, it checks for notifications permissions. If it is not ‘denied’ or ‘granted’ a small window pops up explaing that notifications are fun yadayadayada. Only if the user accepts the app calls up to PushAlert, and PushAlert makes the call to the browser APIs to get user consent.
This works and notifcations are working. But some iOS users are seeing my popup over and over again as if they have never accepted notifications before.
First time this happened the permissions check was like this
navigator.permissions.query({name:'notifications'}).then(function(notification_permission) {
if ( notification_permission.state === 'prompt' ) {
//custom popup stuff goes where
}
});
Eventualy we found this link https://developer.apple.com/forums/thread/731412 which states some inconsistency between navigator.permissions.query showing as ‘granted’ and Notification.permission as ‘denied’. Our case was similar except navigator.permissions.query showed ‘prompt’ and Notification.permission showed ‘granted’.
So we changed stuff a little bit and ended up with this
navigator.permissions.query({name:'notifications'}).then(function(notification_permission) {
if ( notification_permission.state === 'prompt' && Notification.permission === 'default' ) {
//custom popup stuff goes where, if the users accepts
//we call PushAlertCO.forceSubscribe() which calls browser stuff;
}
});
This worked for a while but the problem started again. Apparently when the uses opens up my PWA after clicking a notification the problem starts. Found this link reporting the same issue https://www.reddit.com/r/PWA/comments/19ah68p/notificationpermission_on_ios_always_reverts_back
I’ve setup a test page within my app with a couple buttons to test this. One shows what is in Navigation.permission and the other button tests navigator.permissions.query. In this test page Navigation.permission is ‘granted’ and ‘navigator.permissions.query’ is ‘prompt’.
Regular pages in my app waits 600ms before checking permissions and the permissions are ‘default’ and ‘prompt’ which makes my popup appear. Users are getting notifications regardless.
The difference from the test page is the need to click a button to perform the check.
This happens only to iOS/safari users, tests and issues were all on iOS 17.5.1. Feature detections are in place.
What should I do differently? Or is this really broken in iOS/safari?