iPhone Safari上的HTML5 - localStorage存储的数据并不总是持久存在。为什么?

问题描述 投票:10回答:3

我使用HTML5的localStorage编写了一个简单的iPhone Web应用程序。 在2G设备上进行的测试表明,虽然打开的Safari窗口被记住,但在Safari进程被杀死后,使用localStorage存储的数据不会持久存在。

如果我在不同的Safari窗口上的不同站点上,则数据也会丢失,然后我将窗口更改为显示主题中的Web应用程序的位置。当Safari加载页面时,它会自动刷新页面。然后数据丢失。这是一个简单的测试代码:

<html>
<head>
    <meta name="viewport" content="height=device-height, width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
</head>
<body>
<script>
    alert("1:" + localStorage.getItem("test"));
    localStorage.setItem("test", "123");
    alert("2:" + localStorage.getItem("test"));
</script>
</body>

据我所知,数据应该坚持下去! 任何人都可以对这种行为有所了解吗?我该怎么做才能让持久性发挥作用?

谢谢! 汤姆。

iphone safari html5 mobile-safari local-storage
3个回答
2
投票

据Apple(https://developer.apple.com/library/archive/documentation/iPhone/Conceptual/SafariJSDatabaseGuide/Name-ValueStorage/Name-ValueStorage.html#//apple_ref/doc/uid/TP40007256-CH6-SW3)称,Safari 4.0中增加了localStorage支持。

根据维基百科(https://en.wikipedia.org/wiki/Safari_version_history),在iPhone OS 3.0中添加了Safari 4.0。

2G iPhone未预装OS 3.0或更高版本。您的iPhone OS版本很可能太旧了。


1
投票

我认为iPhone Safari中存在本地存储错误。我和你有类似的问题:http://groups.google.com/group/phonegap/browse_thread/thread/746868e928aaba5c


0
投票

我在我的iPhone 3G和Safari上尝试了你的代码,它可以工作。也许您在iPhone上运行旧版Safari?

© www.soinside.com 2019 - 2024. All rights reserved.