javascript - 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);
});
}
解决方案
iOS 中的 PWA 尚未完全支持。它只能做与离线缓存一样多的事情,仅此而已。Apple iOS 的 A2HS 版本仍然是手动的,大多数用户甚至不知道该功能的存在。
如果您想触发该 A2HS 横幅,您将需要执行自定义 JavaScript 事件并弹出自定义 A2HS HTML 横幅以“指导”您的用户如何在其主屏幕上添加站点。
推荐阅读
- docker - 如何从命令行制作 docker-compose 文件
- python - 说下面的代码在 Python3 中实现了多态是否正确?
- git - 在 Flask 中,如果您将生产和开发变量存储在 .gitignore 文件中,您应该如何部署到 Heroku?
- javascript - 有没有一种方法可以显示页面的提要,而无需用户使用 Facebook Javascript SDK 登录?
- javascript - 使用 Google 文档作为数据端点来获取 JSON
- javascript - 单击按钮时关闭电子窗口?
- python - Python 用 pyautogui 保存多张图片
- html - 导航栏中的下拉菜单不起作用
- python - python - 未解决的参考,我不知道为什么?
- c++ - 在布局 C++ QT 中移动小部件