Prevent restarting web applications on iPad

I have a web application running on an iPad. It works in full screen mode. If I switch the task to another application (by double-clicking the home button, etc.), return to my web application, then my web application will restart.

Is there a way to prevent the web application from restarting when it receives focus after switching iPad tasks? Obviously, I just want him to prove himself exactly in the state in which he was when he lost focus.

Thanks.

+6
source share
2 answers

No, It is Immpossible.

The best way to act is to save state in localStorage. If you use, for example. The hash URL to track your status (for example, myApp.html / # loginScreen), you can save this information and then apply it to location.hash, which will send window.onhashchange.

In other words (codes are just an example written on the fly):

1 - save the relevant information in localStorage:

localStorage.setItem("state", "loginScreen"); 

2 - get the value at startup and apply it to the hash:

 location.hash = (localStorage.getItem("state")) ? localStorage.getItem("state") : ""; 

3 - associate an event listener with onhashchange and go from there:

 window.addEventListener("hashchange", function() { if (location.hash.length) { alert("Current state of UI is :"+ location.hash); } }, false); 
+2
source

At least in iOS 4.2.1, 5.1.1, 6.0 and 6.1 this seems possible; I think the answer accepted for this question is incorrect.

The trick is this:

 // Start or resume session session_start(); // Extend cookie life time by an amount of your liking $cookieLifetime = 365 * 24 * 60 * 60; // A year in seconds setcookie(session_name(),session_id(),time()+$cookieLifetime); 

For a more detailed discussion of this strategy, take a look at Maintaining a PHP Session in a Web Application on iPhone

-1
source

Source: https://habr.com/ru/post/893140/


All Articles