最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

iphone - How to Enable Web Push Notification Permissions on iOS for a Django Web App? - Stack Overflow

programmeradmin2浏览0评论

I am building a Django web app for status checking and need real-time background updates using the Web Push API. The web app will be accessed on both Android and iOS devices. To enable push notifications, I am using the Notification API to request user permission.

The implementation works on Windows, Linux, Android, and Mac, but it does not work on iOS. However, I do not want to convert my web app into a Progressive Web App (PWA). I need guidance on how to request notification permissions on iOS and ensure web push notifications function correctly.

Can someone help me find a solution to complete my project?

Current Implementation

I am using the following JavaScript code to request notification permissions from users:

document.getElementById('grant-permission').addEventListener('click', ()=> {
       Notification.requestPermission().then(permission => {
           console.log("permission:", permission);
           if (permission === "granted") {
            console.log("Notifications allowed!");
        } else {
            console.log("Notifications denied!");
        }
    });
});

Issue

This code works as expected on Windows, Linux, Android, and Mac. However, on iOS (Safari), it does not work. The permission prompt does not appear, and notifications are not allowed. What I Have Tried

  1. Tested on different browsers (Safari, Chrome) on iOS.
  2. Confirmed that Web Push API only works for installed PWAs on iOS.
  3. Ensured the code works on other platforms. Is there any way to request notification permissions and send push notifications without converting my web app into a PWA on iOS?

Any help or alternative solutions would be greatly appreciated!

发布评论

评论列表(0)

  1. 暂无评论