从本机iPhone应用程序访问UIWebView本地存储数据

问题描述:

我正在编写一个包含UIWebView组件的原生iPhone应用程序。该组件访问互联网webapp,webapp使用HTML5本地存储离线存储数据。

I'm writing a native iPhone app that contains a UIWebView component. This component accesses an internet webapp and the webapp stores data offline using HTML5 local storage.

是否可以从本机应用程序访问本地存储数据?

Is it possible to access this local storage data from the native app ?

我当时希望做类似的事情。简而言之,DOM和所有元素都不能直接访问。但是,您可以通过破解来获取数据。您需要做的是将自己的javascript注入下载的网页。然后评估结果。

I was looking to do something similar to this. In short, the DOM and all elements are not directly accessible. However, you can hack things up to get at the data. What you have to do is inject your own javascript into the downloaded webpage. Then evaluate the results.

此页面显示了执行此操作的机制:

This page shows the mechanism for doing it:

http://iphoneincubator.com/blog/windows-views/怎么注入-javascript-functions-into-aiwebview

然后你只需要知道数据库的名称并创建一些javascript到返回JSON字符串中的值。使用cocoa JSON解析器从该字符串创建可在本机应用程序中使用的对象。

Then you just need to know the name of the database and create some javascript to return the values in a JSON string. Use a cocoa JSON parser to create objects from that string that you can use in your native app.