iOS preserve state of UIWebView?

大城市里の小女人 提交于 2020-01-01 03:24:15

问题


Is it possible to preserve the state of the UIWebView (e.g the current webpage, back/front list) in the current app launch? For example, if I dealloc a webview, and at some point in the future, I want to recreate it - is it possible to give it the prior state?


回答1:


Good Approach

In iOS 6 and later, if you assign a value to this view’s restorationIdentifier property, it attempts to preserve its URL history, the scaling and scrolling positions for each page, and information about which page is currently being viewed. During restoration, the view restores these values so that the web content appears just as it did before. For more information about how state preservation and restoration works, see iOS App Programming Guide.




回答2:


You could try caching the web page, this should get you started. Also, you could try and save the HTML string of the webpage and then use loadHTMLString:baseURL: method of the UIWebView class. Or you could try and give it a shot with passing the NSURLRequestReturnCacheDataElseLoad as the cache policy of your NSURLRequest, which should cache the data loaded and try to use it whenever it will be requested again.

Good luck!



来源:https://stackoverflow.com/questions/20960260/ios-preserve-state-of-uiwebview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!