Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
491 views
in Technique[技术] by (71.8m points)

ipad - How to clear back forward list in UIWebview on iPhone?

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?

I've tried:

while ([webview canGoback]) {
    [webview goBack];
}

but that will freeze the device (simulator too).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Disclaimer
As with anything like this, bear in mind that the results may not make it through app store approval and may not work at-all with future revisions of the SDK.


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:

Given that myUIWebViewInstance is a perfectly normal instance of UIWebView:

id internalWebView=[[myUIWebViewInstance _documentView] webView];       
[internalWebView setMaintainsBackForwardList:NO];
[internalWebView setMaintainsBackForwardList:YES];

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...