How to clear back forward list in UIWebview on iPhone?(如何在 iPhone 上的 UIWebview 中清除后退列表?)
问题描述
我想访问/清除后退列表,就好像 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 中清除后退列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 iPhone 上的 UIWebview 中清除后退列表?
基础教程推荐
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
