简体   繁体   English

iPhone苹果浏览器Web应用程序背景

[英]iphone safari web app backgrounding

I'm developing an iPhone web app following some of the suggestions that can be found here : http://matt.might.net/articles/how-to-native-iphone-ipad-apps-in-javascript/ . 我正在按照以下建议在开发iPhone Web应用程序: http : //matt.might.net/articles/how-to-native-iphone-ipad-apps-in-javascript/ In particular, I have designed it to open in a full screen window without the Safari address bar using 特别是,我将其设计为在不使用Safari地址栏的情况下在全屏窗口中打开

<meta name="apple-mobile-web-app-capable" content="yes" />.

On my own iPhone 4, when I test this is produces odd behavior. 在我自己的iPhone 4上,当我测试这会产生奇怪的行为。 Unlike other apps and Safari, when I move away from this app it doesn't background; 与其他应用程序和Safari不同,当我离开此应用程序时,它没有背景。 it doesn't save the execution state. 它不保存执行状态。 It just loses everything. 它只会失去一切。 If I switch to something else on my phone and then come back to my web app, it launches it again fresh. 如果我切换到手机上的其他内容,然后返回到我的Web应用程序,它将再次重新启动它。 So, here are some individual questions that make up my confusion: 因此,以下一些个人问题使我感到困惑:

1) Is this standard behavior or something weird that is happening on my phone? 1)这是我的手机上发生的这种标准行为还是奇怪的事情? That is, if you have specific knowledge about the iPhone and know that this shouldn't happen, I'd be interested to know. 也就是说,如果您对iPhone有特定的了解,并且知道不应该发生这种情况,那么我很想知道。 Otherwise, 除此以外,

2) Can anything be done to change this? 2)可以做些什么来改变这个吗? Can I make it save the current state in the same way that it does within Safari? 是否可以像在Safari中一样保存当前状态?

The Safari developer documentation is strangely silent on this. Safari开发人员文档对此却保持沉默。

This is a standart behaviour. 这是标准行为。 as mentioned here: Prevent web app restart on iPad task switch You have to save the state into localStorage and check it on start up and fake the state. 如此处所述: 防止在iPad任务开关上重新启动Web应用程序您必须将状态保存到localStorage中,并在启动时进行检查并伪造状态。

At least under iOS 4.2.1, 5.1.1, 6.0 and 6.1, this does seem possible; 至少在iOS 4.2.1、5.1.1、6.0和6.1下,这确实可行; 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 有关此策略的详细讨论,请查看iPhone上的Web应用程序中的PHP维护会话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM