HTML5 离线应用程序总是发送“错误” iPod Touch iOS 4.2.1 上的事件
我在 iOS 中使用 HTML5 离线应用程序时遇到问题。我的应用程序可以在 Firefox、Chrome 和 Android 2.2 中离线运行,但不能在运行 iOS 4.2.1 的 iPod Touch 上运行。
这是我的清单(一个 JSP),名为“1.cache.manifest.jsp”。我使用“no-cache.jsp”JSP 来请求不缓存清单。我还将“index.jsp”添加到清单中,但这并不是必需的,因为它是引用清单的资源。
<%@page contentType="text/cache-manifest; charset=UTF-8" pageEncoding="UTF-8"
%><jsp:include page="no-cache.jsp" flush="true"
/><%
String cacheManifestVersion = "20110220 1224";
//System.out.println("Cache manifest version=" + cacheManifestVersion);
%>CACHE MANIFEST
index.jsp
cache-this.js.jsp
这是我的index.jsp 页面。它侦听 applicationCache 事件并转储事件类型。我使用“no-cache.jsp”JSP 来请求不缓存 HTML。
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"
%><jsp:include page="no-cache.jsp" flush="true"
/><!DOCTYPE html>
<html manifest="1.cache.manifest.jsp">
<head>
<script>
var appCacheEvents = ["checking", "error", "noupdate", "downloading", "progress", "updateready", "cached", "obsolete"];
for (var i = 0; i < appCacheEvents.length; i++) {
applicationCache.addEventListener(appCacheEvents[i], function (evt) {
var el = document.getElementById("applicationCache-events");
el.innerHTML += "applicationCache " + evt.type + " event.<br/>";
}, false);
}
</script>
<script src="./cache-this.js.jsp"></script>
</head>
<body>
<div id="applicationCache-events"></div>
<div id="cache-this-output"></div>
</body>
</html>
“cache-this.js.jsp”是一些 javascript,它在加载时向页面添加一些文本:
<%@page contentType="application/javascript; charset=UTF-8" pageEncoding="UTF-8"
%><jsp:include page="no-cache.jsp" flush="true"
/>// cache this
window.addEventListener("load", function (evt) {
var msg = "Script loaded " + new Date();
document.getElementById("cache-this-output").innerHTML = msg;
}, false);
这是那些工作的用户代理的输出,第一次访问该站点时:
applicationCache checking event.
applicationCache downloading event.
applicationCache progress event.
applicationCache progress event.
applicationCache cached event.
Script loaded Sun Feb 20 2011 13:22:33 GMT+0000 (GMT Standard Time)
随后的输出是:
applicationCache checking event.
applicationCache noupdate event.
Script loaded Sun Feb 20 2011 13:23:47 GMT+0000 (GMT Standard Time)
离线时(在 Firefox 中)我得到以下信息。请注意“错误”事件,但该应用程序可以离线工作(即使在我清除 HTTP 缓存之后)。
applicationCache checking event.
applicationCache error event.
Script loaded Sun Feb 20 2011 13:26:54 GMT+0000 (GMT Standard Time)
在我的 iPod Touch 上,我得到相同的输出(与首次访问相同),只是“缓存”事件被“错误”事件替换。
知道为什么 iOS 最初无法缓存应用程序吗?
I have an issue in iOS with a HTML5 Offline app. My app works fine offline in Firefox, Chrome and Android 2.2, but not on my iPod Touch running iOS 4.2.1.
Here is my manifest (a JSP), called "1.cache.manifest.jsp". I use a "no-cache.jsp" JSP to ask that the manifest is not cached. I also add "index.jsp" to the manifest, though this is strictly not necessary as it is the resource that references the manifest.
<%@page contentType="text/cache-manifest; charset=UTF-8" pageEncoding="UTF-8"
%><jsp:include page="no-cache.jsp" flush="true"
/><%
String cacheManifestVersion = "20110220 1224";
//System.out.println("Cache manifest version=" + cacheManifestVersion);
%>CACHE MANIFEST
index.jsp
cache-this.js.jsp
Here is my index.jsp page. It listens to the applicationCache events and dumps out the event type. I use a "no-cache.jsp" JSP to ask that the HTML is not cached.
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"
%><jsp:include page="no-cache.jsp" flush="true"
/><!DOCTYPE html>
<html manifest="1.cache.manifest.jsp">
<head>
<script>
var appCacheEvents = ["checking", "error", "noupdate", "downloading", "progress", "updateready", "cached", "obsolete"];
for (var i = 0; i < appCacheEvents.length; i++) {
applicationCache.addEventListener(appCacheEvents[i], function (evt) {
var el = document.getElementById("applicationCache-events");
el.innerHTML += "applicationCache " + evt.type + " event.<br/>";
}, false);
}
</script>
<script src="./cache-this.js.jsp"></script>
</head>
<body>
<div id="applicationCache-events"></div>
<div id="cache-this-output"></div>
</body>
</html>
The "cache-this.js.jsp" is some javascript that adds some text to the page when loaded:
<%@page contentType="application/javascript; charset=UTF-8" pageEncoding="UTF-8"
%><jsp:include page="no-cache.jsp" flush="true"
/>// cache this
window.addEventListener("load", function (evt) {
var msg = "Script loaded " + new Date();
document.getElementById("cache-this-output").innerHTML = msg;
}, false);
This is the output on those user agents that work, the FIRST time the site is accessed:
applicationCache checking event.
applicationCache downloading event.
applicationCache progress event.
applicationCache progress event.
applicationCache cached event.
Script loaded Sun Feb 20 2011 13:22:33 GMT+0000 (GMT Standard Time)
Subsequently the output is:
applicationCache checking event.
applicationCache noupdate event.
Script loaded Sun Feb 20 2011 13:23:47 GMT+0000 (GMT Standard Time)
And when offline (in Firefox) I get the following. Note the "error" event, but the app DOES work offline (even after I clear the HTTP cache).
applicationCache checking event.
applicationCache error event.
Script loaded Sun Feb 20 2011 13:26:54 GMT+0000 (GMT Standard Time)
On my iPod Touch I get the same output (as first access) EXCEPT the "cached" event is replaced by an "error" event.
Any ideas why iOS is failing to cache the app initially?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您收到错误时,您能看到您的状态返回了什么吗?这是我使用的类似功能,它返回一些可能帮助您排除故障的附加变量:
Can you see what your status is returning when you're getting your errors? Here's a similar functionality I use, that returns a few additional variables that might help you troubleshoot on your end:
我用它来查看 Ipad、iPhone 或 iPod Touch 上的错误结果
I use this to see the error results on the Ipad, iPhone ot iPod Touch