iPhone Web 应用程序 - 会话和会话接听电话后当前网址丢失
我有一个多页面网站,旨在作为 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 应用程序的标准方法是使用类似 Sencha 的界面) 。
从 iPhone 主屏幕启动时,它工作得非常好,并且与通过 Safari 查看时的工作方式相同。
然而,当会议中途接听电话时,似乎出现了一个问题。
通话完成后,iPhone(本例中为版本 4)将恢复到网络应用程序,但不会恢复之前查看的页面,而是重新加载主屏幕(与启动网络应用程序时加载的页面相同) )
当在 Safari 中查看网站并接受呼叫时,它不会执行此操作并维护 URL 和当前会话值。
这是网络应用中的已知问题吗?有解决方法吗?
(我的一个想法是在本地 SQLite 数据库中维护会话和 url 值,但我不确定这是否是最好的方法)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
诀窍是这样做:
我测试了它在 iOS 4.2.1、5.1.1、6.0 和 6.1 上的工作情况。关闭并重新启动设备后,会话甚至会恢复。
有关此策略的更详细讨论,您可以查看我对此问题的回答:
在 iPhone 上的 Web 应用程序中维护 PHP 会话
The trick is to do this:
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
不要将登录信息存储在 $_SESSION 变量中,而是将其存储在 $_COOKIE 中。 Cookie 将根据您设置的过期时间进行保存。只要他们在网络应用程序“内部”或常规网络版本(并且 cookie 相同)登录,他们就不必每次或在两者之间切换时登录。
Instead of storing the login info in a $_SESSION variable, store it in a $_COOKIE. The cookie will be saved depending on when you set it to expire. As long as they log in "inside" the web app, or the regular web version (and the cookie is the same) they will not have to log in every time or when switching between the two.
我在 iOS v10 下的 WebApp 也遇到了同样的问题。这不是会话和/或 cookie 的问题(会话机制没问题,基于具有足够生命周期的 cookie)。
问题是在 WebApp 模式下运行时(即从桌面快捷方式启动应用程序,而不是在 Safari 中启动),切换到另一个应用程序时(例如接听电话),“上下文”会丢失。当你回到应用程序时,请求的URL不是最后一个,而是保存到桌面快捷方式中的URL...
在我的例子中,快捷方式是从登录屏幕创建的,所以每次我切换回我的应用程序来自另一个应用程序,它是名为 /login URL...看起来我已注销...
因此请小心您的网络应用程序上的 URL 快捷方式。
目前,我还没有找到在用户创建快捷方式时指定特定 URL 的方法。
I haved the same problem with my WebApp under iOS v10. It was not a problem of session and / or cookie (session mecanism was OK, based on a cookie with suffisant lifetime).
The problem is when running in WebApp mode (i.e. application launch from a desktop shortcut, not whithin Safari), the "context" is lost when switching to another app (for example answer a call). When you come back to the app, the requested URL is not the last one, but it is the URL saved into the desktop shortcut...
In my case, the shortcut was made from the login screen , so every time I switched back to my app from another app, it was the /login URL called... It looks like I was logged out...
So be careful of the URL shortcut on your web app.
At this point, I have not found a way to specify a specific URL when the user create the shortcut.