我想访问/清除后退列表,就好像 UIWebView
又是新的一样.是否有任何公共 API 或解决方法可以做到这一点?
I want to access/clear the back forward list as if the UIWebView
is new again. Is there any public API or workaround to do this?
我试过了:
while ([webview canGoback]) {
[webview goBack];
}
但这会冻结设备(模拟器也是).
but that will freeze the device (simulator too).
免责声明
与任何类似的事情一样,请记住,结果可能无法通过应用商店的批准,并且可能根本不适用于 SDK 的未来修订版.
SDK 中没有官方 方法可以做到这一点.但是,如果您真的想清除 UIWebView
的后退/前进历史记录,可以通过深入研究私有框架来完成.
There is no official method for doing this in the SDK. However if you really want to clear the back/forward history of a UIWebView
it can be done with a little delve into the private frameworks.
一个快速而肮脏的方法(完成一堆丑陋的编译器警告)如下:
A quick and dirty way to do it (complete with a bunch of ugly compiler warnings) is as follows:
鉴于 myUIWebViewInstance
是一个完全正常的 UIWebView
实例:
Given that myUIWebViewInstance
is a perfectly normal instance of UIWebView
:
id internalWebView=[[myUIWebViewInstance _documentView] webView];
[internalWebView setMaintainsBackForwardList:NO];
[internalWebView setMaintainsBackForwardList:YES];
框架中还有一个比较诱人的_clearBackForwardCache
方法,不过在tick的时候好像没什么作用.只是翻转布尔值对我来说是一种享受.
There is also the rather tempting _clearBackForwardCache
method in the framework, however it didn't seem to do much when tickled. Just flipping the boolian worked a treat for me.
这篇关于如何在 iPhone 上的 UIWebview 中清除后退列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!