如何通过主屏幕书签(嵌入)检测到正在访问该应用程序? [英] How to detect that the application is being visited through a homescreen bookmark (embedded)?

查看:85
本文介绍了如何通过主屏幕书签(嵌入)检测到正在访问该应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用expo SDK36编写一个react native应用程序.

I am writing a react native application with expo SDK36.

当用户访问该网站时,清单与飞溅和图标一起使用,以生成一个不错的PWA.

When a user visit the website, the manifest is used with splash and favicon to produce a nice PWA.

如果我在主屏幕上添加带有野生动物园或Chrome的书签,则无需安装任何商店,也无需浏览器的搜索栏,我的应用程序就可以使用.

If I add a bookmark on my home screen with safari or chrome, I get my application available without any store installation and without the search bar from the browser.

如何检测该应用程序是否在嵌入式Webview中运行?

How can I detect that the app is running in an embedded webview ?

推荐答案

您可以使用显示模式来检测Web应用程序是在浏览器中运行还是独立运行.

You can detect whether your web app is running in browser or as standalone using display mode.

如果您要出于样式目的检测显示模式,请阅读

If you want to detect the display mode for styling purpose then read here.

或者,您可以通过javascript检测显示模式,如下所示.

Alternatively, you can detect display mode via javascript as below.

  if (window.matchMedia('(display-mode: standalone)').matches) {
                 console.log("This is running as standalone.");
     }

另一种简单的方法是,您可以将查询字符串附加到起始url上,以检测PWA是否正在运行.

Another simple way is you can append a query string to your start url to detect if, PWA is running.

  "start_url": "./?mode=standalone"

这篇关于如何通过主屏幕书签(嵌入)检测到正在访问该应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆