Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

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.

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
217 views
Welcome To Ask or Share your Answers For Others

1 Answer

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>

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...