Notification.requestPermission() not prompting allow / deny on iOS Safari 16.5
Asked Answered
F

2

9

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?

Fatherland answered 16/6, 2023 at 20:23 Comment(1)
Did you solve this? I have same issues, also safari works on mac for me on mac perfectly. On mac FF and chrome req extra settings, but I at least get the initial popup. On iphone I get nothing at all.Felisha
R
0

I know it's too late but have added "display": "standalone" inside your manifest.json file. Also make sure this <link rel="manifest" href="manifest.json"> code exists inside <head></head> tag of your index.html file.

After doing this, you have to clear all your site's website data (cache) from Safari history. Then add your site to the Home Screen. It should work after that. According to this, it’s a requirement to add the app to the home screen for push notifications. Once users install your app on the home screen, it will receive push notifications.

Rodgers answered 29/12, 2023 at 5:18 Comment(0)
H
0

be careful to be connect in https://

Hypozeuxis answered 6/8 at 17:11 Comment(1)
Welcome to StackOverflow. Please, edit and try for How to Answer, describe the effect of what you propose and explain why it helps to solve the problem. Consider taking the tour.Smoky

© 2022 - 2024 — McMap. All rights reserved.