微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PWA 应用程序 beforeInstallPrompt 不触发其他浏览器只触发 Chrome 浏览器

如何解决PWA 应用程序 beforeInstallPrompt 不触发其他浏览器只触发 Chrome 浏览器

在 PWA Reactjs 应用程序中 beforeinstallprompt 仅在 Chrome 移动和桌面浏览器中触发。我想像 Chrome 一样触发或触发其他浏览器。我做错了什么。

在 App.js 中添加带有 useEffect 的 EventListener。

   useEffect(() => {
        window.addEventListener("beforeinstallprompt",(e) => {
            // Prevent the mini-infobar from appearing on mobile
            e.preventDefault();
            // Stash the event so it can be triggered later.
            deferredPrompt = e;
            // Update UI notify the user they can install the PWA
            setInstallable(true);
        });

        window.addEventListener('appinstalled',() => {
            // Log install to analytics
            console.log('INSTALL: Success');
        });
    },[]);

但不触发其他浏览器只触发chrome浏览器...

解决方法

beforeinstallprompt 事件目前仅在 Chrome、Edge 和 Samsung Internet 中触发。 Safari 允许用户安装 PWA,但用户必须通过点击共享按钮,然后添加到主屏幕来自己安装。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。