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

Aer*_*yne 10 iphone safari html5 mobile-safari local-storage

我使用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>
Run Code Online (Sandbox Code Playgroud)

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

谢谢!
汤姆.

Ale*_*lex 0

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