我想知道是否可以检测iOS用户是否正在使用webapp,或者只是使用safari浏览器访问正常方式.
我想要实现的原因是,当用户点击链接时,在iOS webapp上,他将被重定向到Safari浏览器.所以我使用以下解决方法让他留在webapp(阻止切换到safari浏览器).
$( document ).on("click",".nav ul li a",
function( event ){
// Stop the default behavior of the browser, which
// is to change the URL of the page.
event.preventDefault();
// Manually change the location of the page to stay in
// "Standalone" mode and change the URL at the same time.
location.href = $( event.target ).attr( "href" );
}
);
Run Code Online (Sandbox Code Playgroud)
但我希望这种解决方法只在用户使用webapp时发生,我希望它对webapp用户有条件.所以不在默认的safari浏览器上.
去年webkit 删除了iOS的350毫秒延迟.当我在Safari的移动浏览器中运行我的网站时,延迟不再存在,并按预期工作.
但是,当我在独立模式下运行我的Web应用程序时,延迟存在,并且显而易见.
这是我正在使用的元标记:
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, maximum-scale=1, width=device-width">
Run Code Online (Sandbox Code Playgroud)
我尝试了各种各样的变种,没有运气.
很难找到关于独立应用程序的任何东西,不过这个明显的问题.
有谁知道为什么这个350ms延迟点击只发生在独立模式?作为一种解决方法,我不得不将fastclick带入项目,这并不理想.
注意:我正在运行iOS 9.3.5/iPhone 6
standalone用于在 Chrome Android 中检测模式的方法在我的 PWA 中均不起作用
这是我尝试过的CSS方法
@media all and (display-mode: standalone) {
/* Here goes the CSS rules that will only apply if app is running standalone */
}
Run Code Online (Sandbox Code Playgroud)
这是 Javascript 方法(第 171-175、297-306 行)
function isRunningStandalone() {
return (window.matchMedia('(display-mode: standalone)').matches);
}
...
if (isRunningStandalone()) {
/* This code will be executed if app is running standalone */
}
Run Code Online (Sandbox Code Playgroud)
它们都不起作用:isRunningStandalone()在 Chrome Android 中进行远程测试会返回false,尽管该示例有效。
(这里是 @josemmo 制作的示例)
我已经在 iOS 和 3 部不同的 Android 手机中测试了代码。iOS …
我有一个 PWA 应用程序,我在其中检查应用程序是否处于独立模式(下面的代码片段),否则提示用户安装横幅。
let windowNav: any = window.navigator;
if (window.matchMedia('(display-mode:standalone)').matches || windowNav.standalone) {
this.isStandAlone = true;
}
Run Code Online (Sandbox Code Playgroud)
最近,我还为此创建了一个 TWA 应用程序。现在,当我从 Playstore 安装应用程序时,尽管应用程序处于独立模式,但以下检查失败。是否有不同的方法来检查 TWA 应用程序中的独立模式?或者检查该应用程序是否是 TWA 应用程序的方法?
谢谢