首页 > 解决方案 > ios中的PWA,防止多次添加主屏幕

问题描述

PWA 应用程序在 ios 中无法正常工作,如在 android 中,如果您下次将应用程序添加到主屏幕中,它将不允许您添加它会显示消息,例如应用程序已安装在您的手机中,但在 ios 中它允许如果用户已经拥有应用程序,那么添加 n 次是不好的,那么他们为什么要多次添加它。

有人可以帮我吗?我们能解决这个问题吗?请提出类似的建议,它是 ios 对 pwa 的限制吗!

const isIos = () => {
      const userAgent = window.navigator.userAgent.toLowerCase();
      return /iphone|ipad|ipod/.test(userAgent);
    }
    const isInStandaloneMode = () => ('standalone' in window.navigator) && (window.navigator.standalone);
    if (isIos() && !isInStandaloneMode()) {
        var deferredPrompt;
        window.addEventListener('beforeinstallprompt', function (e) {
          // Prevent Chrome 67 and earlier from automatically showing the prompt
          e.preventDefault();
          // Stash the event so it can be triggered later.
          deferredPrompt = e;
              var display = true;
            setInterval(function () {
            document.getElementById("balloonMessage").style.display = display ? "none" : "block";
            display = !display;
          }, 5000);      
        });
    }    

标签: javascriptangularjsasp.net-mvcpolymer-1.0progressive-web-apps

解决方案


iOS 中的 PWA 尚未完全支持。它只能做与离线缓存一样多的事情,仅此而已。Apple iOS 的 A2HS 版本仍然是手动的,大多数用户甚至不知道该功能的存在。

如果您想触发该 A2HS 横幅,您将需要执行自定义 JavaScript 事件并弹出自定义 A2HS HTML 横幅以“指导”您的用户如何在其主屏幕上添加站点。


推荐阅读