简体   繁体   English

即使在安装应用程序之后,`beforeinstallprompt` 事件也会触发

[英]`beforeinstallprompt` event is firing even after the app is installed

I'm showing a custom PWA install popup to the user using beforeinstallprompt event before showing the native install popup.在显示本机安装弹出窗口之前,我使用beforeinstallprompt事件向用户显示自定义 PWA 安装弹出窗口。 For some of our users, who already installed the PWA to their desktop, are getting the custom popup again.对于我们的一些用户,他们已经将 PWA 安装到他们的桌面上,他们再次获得自定义弹出窗口。 The only way for that happening is that the beforeinstallprompt event is firing again.发生这种情况的唯一方法是beforeinstallprompt事件再次触发。 Is that possible?那可能吗?

Will browser fire beforeinstallprompt event even when PWA is installed to the user system?即使 PWA 安装到用户系统,浏览器beforeinstallprompt会触发beforeinstallprompt事件?

Issues are reported for Google Chrome.报告了 Google Chrome 的问题。

Actually, I came across this issue today.事实上,我今天遇到了这个问题。 Hope I'm not late to the party.希望我没有迟到。 Anyway, what I did was that I listened to the event fired when a user has successfully accepted the installation of the "app" then I hid the custom install button.无论如何,我所做的是当用户成功接受“应用程序”的安装时我听到了触发的事件,然后我隐藏了自定义安装按钮。 This is because chrome automatically launches the installed "app".这是因为 chrome 会自动启动已安装的“应用程序”。

Actually, before showing the user the button to install your app, check if the app was first launched via the app itself or directly from the browser using:实际上,在向用户显示安装应用程序的按钮之前,请检查应用程序是首先通过应用程序本身启动还是直接从浏览器启动:

 if(windows.matchMedia.("(display-mode:standalone)").matches)
{
    //do not show the button
}.

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM