PHP Classes

Not working on iOS (Chrome or Safari)

Recommend this page to a friend!

      PHP Web Push Notifications Server  >  PHP Web Push Notifications Server package blog  >  How to Use a PHP Push...  >  All threads  >  Not working on iOS (Chrome or Safari)  >  (Un) Subscribe thread alerts  
Subject:Not working on iOS (Chrome or Safari)
Summary:The class does not work with iPhone
Messages:1
Author:Sam Spickle
Date:2020-11-07 14:44:34
 

  1. Not working on iOS (Chrome or Safari)   Reply   Report abuse  
Picture of Sam Spickle Sam Spickle - 2020-11-07 14:44:34
Class worked well out-of-the-box (only complaint is that it was a bit 'here/there' to get config going - I'd like to see a single file for that, but that's personal preference...)

Easy and nice to give notifications on DESKTOP, but nothing working on iPhone (Chrome or Safari).

After hours of searching, it seems to be (yet another... sigh...) that Apple doesn't support notifications except on mac.... (https://support.google.com/chrome/answer/3220216?co=GENIE.Platform%3DiOS&hl=en)

Anyway, here's code that works (yours just hangs and never prints the msg....) so others can know about the issue (you might even want to put a link to the 'facts' page)


in PNTestClient.html around line 17 replace the two lines that have

window.Notification.permission

with

msg += 'Notification.permission: ' + ("Notification" in window) +'<br/><br/>';

// Let's check if the browser supports notifications
if (!("Notification" in window)) {
msg += "This browser does not support desktop notification" +'<br/><br/>';
console.log("This browser does not support desktop notification");
}

// Let's check whether notification permissions have alredy been granted
else if (Notification.permission === "granted") {
// If it's okay let's create a notification
var notification = new Notification("Hi there!");
}

// Otherwise, we need to ask the user for permission
else if (Notification.permission !== 'denied' || Notification.permission === "default") {
Notification.requestPermission(function (permission) {
// If the user accepts, let's create a notification
if (permission === "granted") {
var notification = new Notification("Hi there!");
}
});
}


Also, as an overall simpler way to register the service worker (and works on more browsers) you can use the method from https://stackoverflow.com/questions/31512504/html5-notification-not-working-in-mobile-chrome. I didn't go to the trouble of reworking everything to get there as the only reason I downloaded this class was to work a project on mobile devices (and with iPhone about 45% of the market, that is certainly a requirement!)