关于离线访问

iOS 码拜 9年前 (2015-05-09) 525次浏览 0个评论
 

有个需求,
有网的时候我用UIWebView登录一个网站并存储到特定缓存文件夹,离线的时候我能通过缓存来查看。

1. Loaded the web page in webView.
2. After webViewDidfinishload, I stored the contents into an NSData object and then converted data to an NSString and wrote to a file and saved in the application folder.
3. Now while trying load it, I am taking the string back from the file and converting it back to NSData and loading it to webView using loadData: method.

這是外國英文網站找到的…..
他是在webViewDidfinishload事件中處理,將其儲存
只是從這樣看來,你自己的程序可能要寫判斷機制,判斷是否已存有離線瀏覽

1. The web pages I am trying to save are simple (doesnt have much css and all) and the problem I am facing is that I am not able to load images, since most of the images in an html are external links, it requires net connection to load it. Any idea how to get images too to get saved to my file?

2. The second problem I am facing is how to delete a saved file from app””s folder. I am able to get the list of files in the application””s folder and get it populated in a table view and now I want to delete the file when i do “swipe to delete”

這兩個問題是他碰到的

http://dblog.com.au/iphone-development/iphone-sdk-tutorial-build-your-very-own-web-browser/
上面這一篇,是用UIWebView打造自己的瀏覽器的範例

http://dblog.com.au/iphone-development/loading-local-files-into-uiwebview/
第二篇是如何用UIWebView讀取Local file,也就是你要的離線瀏覽…

这种方法有想过,
除了图片问题,我们还关心工作量的问题,这样做就变的复杂了。
这是我们的最后方案,迫不得已才会用的。
我们现在寄希望于iphone的缓存功能很强大很强大,强大到访问过的网页就可以随时离线访问。

第二个问题是关于删除缓存吗?
这个我们倒不关心,我们的需求导致我们不会遇到这个问题。

我以後也用繁體吧,反正iphone開發版面只有你回答問題。

這種方法有想過,
除了圖片問題,我們還關心工作量的問題,這樣做就使程序複雜了。
這是我們的最後方案,迫不得已才會使用。
我們現在寄希望於iphone的緩存功能很強大很強大,強大到訪問過的網頁就可以隨時離線訪問。

第二個問題是關於刪除緩存嗎?
這個我們倒不關心,因為我們的需求不會使我們遇到這個問題。

其實我只是常常忘了切換簡體….
只是就查到現在的資料來看, IPhone的緩存功能似乎一點都不強大…
那我死定了,
剛在googlecode上搞到freebase的代碼,和離線存儲有關,研究ing。
30分
总会解决的…
加油
運氣好了一點點。

我剛給你說過的那個freebase讓我看到些希望。
http://code.google.com/p/freebase-framework/downloads/list

現在能做到的。
1。UIWebView加載www.baidu.com,加載完成後點擊《新聞》,遷移到《新聞》界面。
2。離線。
3。重啓模擬器,《www.baidu.com》可以離線顯示,《新聞》也可以離線顯示。
問題:圖片沒有顯示。

我這試著解決,應該問題不大。

還有,離線網頁的樣式亂了。

應該是css也沒有下載到local的關係
搞定。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明关于离线访问
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!