如何在 iPhone 上的 UIWebview 中清除后退列表?

2023-10-22移动开发问题
6

本文介绍了如何在 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 中清除后退列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

突出显示朗读文本(在 iPhone 的故事书类型应用程序中)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))...
2024-08-12 移动开发问题
9

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

正确的 cocos2d 场景重启?
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)...
2024-08-12 移动开发问题
7

[ios.cocos2d+box2d]如何禁用自动旋转?
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)...
2024-08-12 移动开发问题
7