开发者

Prevent web app restart on iPad task switch

I have a web app running on an iPad. It is running in full-screen mode. If I task switch to another app (by double-clicki开发者_如何学运维ng the home button etc), then switch back to my web app, then my web app restarts.

Is there any way to prevent the web app from restarting when it receives the focus after an iPad task switch? Obviously I just want it to show itself in exactly the state it was in when it lost focus.

Thanks.


No, this is not possible.

The best way to act is to save a state into localStorage. If you're using eg. URL hash for tracking your state (eg. myApp.html/#loginScreen), one can store that info and then apply it on location.hash which would dispatch window.onhashchange.

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

1 - store relevant information to localStorage:

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

2 - retrieve value on start up and apply it to hash:

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

3 - bind an event listener to onhashchange and proceed from there:

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


At least under iOS 4.2.1, 5.1.1, 6.0 and 6.1, this does seem possible; I think the answer accepted for this question is wrong.

The trick is to do 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 elaborate discussion of this strategy, take a look at Maintain PHP Session in web app on iPhone

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜