当 WebKit WebApp 被“终止"时会触发什么事件? [英] What event fires when a WebKit WebApp is "terminated"

查看:19
本文介绍了当 WebKit WebApp 被“终止"时会触发什么事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 iOS 开发 Web 应用程序,并且正在使用 DOMApplicationCache.我知道 Web Apps 不能在后台运行,但我仍然想在用户切换到另一个应用程序并稍后返回到 Web 应用程序时模拟该应用程序的恢复.

I am in the process of developing a Web App for iOS and am using the DOMApplicationCache. I know that Web Apps can not run in the background, but I still would like to simulate a resume of the app when the user switches to another app and returns to the web app later.

为了做到这一点,我至少需要记录 Web 应用程序何时终止/卸载.但是 window.unload 似乎没有触发.

In order to do this I at least need to record when the Web App terminates/unloads. But the window.unload does not seem to fire.

有人知道如何捕获正在运行的 WebApp 的终止吗?

Does anybody have an idea how to catch the termination of a WebApp running?

PS:在一个相关的问题上,当 apple-mobile-web-app-capable 为 yes 时,console.log 在哪里?

PS: on a related question, where does the console.log go when apple-mobile-web-app-capable is yes?

推荐答案

您可以使用pageshow"事件来检测应用何时恢复.当用户从不同的 safari 选项卡返回您的应用程序时,将触发此事件.当用户单击主页按钮然后通过单击 safari 按钮返回应用程序时,它也会触发

You can use the "pageshow" event to detect when the app has resumed. This event will fire when user returns to your app from a different safari tab. It will also fire when user clicks the home button and then comes back to the app by clicking on safari button

     <script>
    window.addEventListener("pageshow", function(){
        alert("page shown");
    }, false);
  </script>

我已经在 iOS 模拟器上测试了它,并且它的工作原理与我上面描述的一样.

I have tested this on the iOS simulator and its working as I described above.

这篇关于当 WebKit WebApp 被“终止"时会触发什么事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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