我为网站的每个子域都有一个自定义的PWA。想法是在Google Play上安装一个PWA,当安装该PWA时,用户可以选择一个子域,将其重定向到该子域,然后提示他安装与所选子域相关的PWA。
问题是从Google Play(或直接从apk)安装的PWA在WebView中打开,这似乎不会在子域上触发berforeinstallprompt
事件(当我在Google Chrome中打开子域时,该事件被正确触发)。 WebView菜单中的“添加到主屏幕”选项仍然可用。
这给了我两个选择,但是我无法让它们中的任何一个起作用:
1)在Google Chrome(而不是WebWiev)中运行从Google Play安装的PWA。
2)了解如何在WebView中触发berforeinstallprompt
。
有可能吗?怎么样?
捕获berforeinstallprompt
事件并显示安装按钮的代码与https://developers.google.com/web/fundamentals/app-install-banners/上的代码非常相似,因此问题应该出在其他地方。
var deferredPrompt;
var button = document.getElementById("install-button");
window.addEventListener('beforeinstallprompt', (e) => {
e.preventDefault();
deferredPrompt = e;
button.style.display = 'block';
});
最佳答案
仅在某些情况下会触发beforeinstallprompt
,例如,如果您的应用程序已经安装,或者您的网站未满足https中的所有请求。另外,尝试运行lighthouse more tools => developer tools => Audits
并运行,看看您的应用程序是否已优化。
请描述更多您想要实现的目标,为什么要在PWA中使用子域?
关于webview - 如何在Google Chrome(而不是WebView)中从Google Play打开PWA?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56277486/