iOS Safari 16.5 failing to show permission prompt for Notification.requestPermission() prompt

Recently, I have been working on integrating Firebase Cloud Messaging into an iOS Safari browser due to the support for Push Notification and Notification API.

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);
            // ...
         });
      }
   })         
}

When using the requestPermission() function on a desktop, it successfully requests permission without any issues. However, when trying the same on iOS Safari, Notification.requestPermission() does not prompt the user or show errors, even though notifications are enabled in the browser.

The function is triggered by a button click, which seems to prevent any errors related to "user gesture." How can I go about resolving this issue?

Answer №1

Although it may seem like the timing is off, I have inserted

"display": "standalone"
into your manifest.json file. Additionally, please ensure that this
<link rel="manifest" href="manifest.json">
code is present within the <head></head> section of your index.html file.

Once these steps are completed, you must clear all cached website data from Safari history on your site. Subsequently, add your site to the Home Screen. This process should resolve the issue. As per information found here, adding the app to the home screen is necessary for enabling push notifications. When users install your app on their home screens, they will start receiving push notifications.

Answer №2

Always remember to establish a secure connection using https://

Answer №3

I encountered a similar issue, but I was able to resolve it by adding a click listener to trigger the function.

    $(document).on('touchend click', function() {
                requestNotificationPermission();
                // Once permission is requested, remove the event listener
                $(document).off('touchend click');
            });
    function requestNotificationPermission(){
                firebase.initializeApp(config);
                if (firebase.messaging.isSupported()){
                    const messaging = firebase.messaging();
    
                    messaging
                    .requestPermission()
                    .then(() => {
                        message.innerHTML = "Notifications allowed";
                        return messaging.getToken();

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Customize Bootstrap Vue dropdown without any predefined styling options

After reviewing the documentation, I created a sample example utilizing the b-dropdown component: You can view the example here: https://codesandbox.io/s/6lhk6?file=/src/components/GenericItem.vue However, when I implemented the component in the code: &l ...

Can you explain the significance of the role attribute being set to "button"?

While browsing through the Google+ Project's page, I noticed that all the buttons were created using div elements like: <div role="button"></div> I'm curious to know if this is done for semantic reasons or if it has an impa ...

When employing the map function in React, the resulting array is always equal to the last element within

Recently delving into the world of React, I encountered an issue while trying to assign unique ids to an array of objects within a Component's state using the map function. Strangely, despite my efforts, all elements in the resulting array ended up be ...

Inserting data into a table using variables in Mssql database management system

I'm really struggling to find a way to safely add my Variables into an MSSQL server. I've tried everything. Could someone please help me and provide the solution for adding my Variables into the Database? It is crucial that I prevent any possib ...

Text Field: Enhancing VoiceOver Accessibility with Right View

When I add two UIButton elements to the right view of a UITextField, VoiceOver is unable to detect them. It only "reads" the containing view. I've already made sure that the right view's accessibilityElementsHidden property is set to 'no&apo ...

Restricting JQuery pop-up to be shown only once

I'm looking for a solution to have a pop-up appear only once when the mouse leaves the screen. I'm not very experienced with coding, so I'm struggling to figure out how to achieve this. // Implementing Exit Intent function addEvent(obj, ev ...

Comparing datetime in SQLite

Is there a simple method in an iOS app to compare datetime strings in sqlite3? I have been storing datetime strings like this: NSDateFormatter* df=[[NSDateFormatter alloc] init]; [df setDateFormat:@"yyyy-MM-dd HH:mm"]; NSString* dtString=[df strin ...

Using jQuery to attach events and trigger them

Within my code, I have the following scenarios: $("#searchbar").trigger("onOptionsApplied"); And in another part of the code: $("#searchbar").bind("onOptionsApplied", function () { alert("fdafds"); }); Despite executing the bind() before the trigge ...

Include row identification and row information using a multidimensional array structure

When working with the jQuery DataTables plugin, you have the option to utilize arrays of objects or arrays of arrays. It appears from this source that using the object format comes with reserved keys that are managed by the plugin. In my case, I prefer us ...

Schema for Monogo Database

My goal was to have a property that could give me the timestamp of when a specific task was created. I decided to add a timestamp property and set it to true, but now my code won't compile. The code is functioning perfectly fine without the timestamp ...

jaydata integration with sorting capabilities

Utilizing JayData, I am fetching a table along with other tables through a join operation. The code I have written is as follows: db.Table1.include("Table2").include("Table3").toArray(); However, my issue arises when I try to sort the data based on a fi ...

Tips for interpreting the JSON data returned by a Node server in Angular

When trying to implement a login form in my Angular frontend, I encountered an issue with reading the JSON object returned from my node.js server. Despite following the correct steps, the console displays "undefined" as if it cannot recognize the format. ...

Increasing several array elements within a MongoDB object

I have been struggling with this problem for some time now. My goal is to update multiple array values in the same object with a single query. The data in the database appears as follows: id: 616f5aca5f60da8bb5870e36 title: "title" recommendations: ...

Error in Angular 2: The app.component.html file triggered an exception at line 1, character 108 due to excessive recursion

After successfully setting up the Angular 2 quickstart and connecting to an express server, I encountered a problem when switching from using the template property to component templateUrl. I have created a Plunker to showcase this issue: Plunker Demo imp ...

Issue with updating array of objects in Typescript when working with dates

In my TypeScript function, I am working with query parameters to update an object based on certain conditions. The function loops over the existing set of query parameters and updates the object if it finds a matching parameter name. It's important t ...

Sending location information from Windows to iOS devices

I am looking to establish a connection between a Windows 7 computer and an iOS device for data sharing. Since Wifi doesn't seem plausible, I am considering simulating a Bluetooth GPS device on my Windows 7 computer so that the iOS device can connect t ...

Display a bootstrap toast using a JavaScript class method

One way to display a bootstrap toast is by using the following code snippet: let my_toast = new myToast('title', 'hello world'); my_toast.show(); Currently, I am loading the HTML content from an external file named myToast.html: < ...

What is the best way to update a deeply nested array of objects?

I have an array of objects with nested data that includes product, task, instrument details, and assets. I am attempting to locate a specific instrument by supplier ID and modify its asset values based on a given number. const data = [ { // Data for ...

Split the text using the newline character (' ') and not the double newline character (' ')

Looking to create a filter that separates all \n and combines them back as \n\n. Is it possible to only target the single \n without affecting the double \n\n? Currently, the issue arises when the input field loses focus, caus ...

Having two ng-click events and two distinct classes in an ng-repeat based on the selected option

There are two buttons in my code that should remove a div within an ng-repeat loop. Depending on which button is clicked, a custom CSS class should be added to the effect. The CSS changes based on the option selected. When I click on a button, either &apo ...