I am attempting to implement Firebase Cloud Messaging in an iOS Safari browser since Push Notification and Notification API are now supported.
function requestPermission() {
console.log("request permission")
Notification.requestPermission().then((permission) => {
if (permission === 'granted') {
console.log('FIREBASE CLOUD MESSAGING Notification permission granted.');
messaging.getToken(messaging, { vapidKey: '<my-key>' }).then((currentToken) => {
if (currentToken) {
// Send the token to your server and update the UI if necessary
// ...
console.log("FIREBASE CLOUD MESSAGING currentToken", currentToken)
} else {
// Show permission request UI
console.log('FIREBASE CLOUD MESSAGING No registration token available. Request permission to generate one.');
// ...
}
}).catch((err) => {
console.log('FIREBASE CLOUD MESSAGING An error occurred while retrieving token. ', err);
// ...
});
}
})
}
I use the function requestPermission()
from desktop and it successfully requests permission. However, on iOS Safari, Notification.requestPermission()
does not show errors or prompts for the user even though notification is defined in the browser and Push Notification and Notification API are enabled.
I have this function called by a button click, which has prevented me from getting errors about "user gesture."
How can I resolve this issue?