iPhone Web App-会话和接听电话时当前网址丢失 [英] iPhone Web App - Session & Current url lost when call answered

查看:100
本文介绍了iPhone Web App-会话和接听电话时当前网址丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多页网站,旨在用作iPhone上的网络应用程序.

它具有通常的功能:

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<link rel="apple-touch-startup-image" href="/images/startup.png" /> 

该网站不使用Sencha或Javascript在页面之间导航,仅使用标准锚链接和页面重新加载(我知道,Web应用程序的标准方法是使用类似Senc​​ha的界面)./p>

从iPhone主屏幕启动时,它的工作效果非常好,并且与通过Safari浏览时的效果相同.

但是,在会话中接听电话时似乎出现了一个问题.

通话完成后,iPhone(在本例中为第4版)将恢复为网络应用,但不是还原先前查看的页面,而是重新加载了主屏幕(与应用已启动)

在Safari中查看网站并接受呼叫时,它不会执行此操作,并且会保留url和当前会话值.

这是网络应用程序中的已知问题吗?有解决方法吗?

(我的一个想法是在本地SQLite数据库中维护会话和url值,但是我不确定这是否是最好的方法)

解决方案

诀窍是做到这一点:

// 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);

我对此进行了测试,可以在iOS 4.2.1、5.1.1、6.0和6.1上运行.关闭并重新启动设备后,会话甚至可以恢复.

要对该策略进行更详细的讨论,您可以看一下我对这个问题的回答: 在iPhone上的Web应用程序中维护PHP会话

I have a multi-page website that is designed to work as a web-app on an iPhone.

It has the usual:

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<link rel="apple-touch-startup-image" href="/images/startup.png" /> 

The site doesn't use Sencha or Javascript to navigate between pages, just standard anchor links, and page-reloads (I'm aware that the standard approach to web-apps is to use a Sencha-like interface).

It works perfectly fine when launched from the iPhone homescreen, and works the same as when viewed through Safari.

An issue seems to arise, though, when a phone call is answered mid-session.

Once the call is complete, the iPhone (version 4 in this case) reverts back to the web-app, but instead of restoring the previously-viewed page it reloads the homescreen (the same page that is loaded when the web-app is initiated)

When viewing the site in Safari, and accepting a call, it doesn't do this and maintains the url and current session values.

Is this a known issue in web-apps? Is there a workaround?

(one idea I have is to maintain the session and url values in a local SQLite database, but I'm not sure if this is the best approach)

解决方案

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);

I tested this to work on iOS 4.2.1, 5.1.1, 6.0 and 6.1. The session is even restored after turning off and restarting the device.

For a more elaborate discussion of this strategy you can take a look at my answer of this question: Maintain PHP Session in web app on iPhone

这篇关于iPhone Web App-会话和接听电话时当前网址丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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