How to pull out browsing history from uiwebview ip

2019-07-25 07:21发布

How can i get the browsing history in UIWebView Iphone. UIWebView recorded browsing history ? if yes, How to pull out back this history shown in table view as Safari .

Please advice me. Any suggestion.

Thanks

2条回答
We Are One
2楼-- · 2019-07-25 07:42

It's actually much simpler than creating your own stack (which is what I was about to do until I found that it's not necessary). UIWebView has the methods: goBack, goForward, canGoBack and canGoForward. You can do the following.

Make the ViewController that contains your UIWebView a delegate of UIWebViewDelegate:

Create the IBActions for the buttons:

- (IBAction) browserBack: (id)sender
{
    [webBrowser goBack];
}

- (IBAction) browserForward: (id)sender
{
    [webBrowser goForward];
}

Create your Back and Forward buttons and link them to the IBActions as well as to the appropriate IBOutlets

Finally add the webViewDidFinishLoad delegate method:

- (void) webViewDidFinishLoad: (UIWebView *)webView
{
    [mBackButton setEnabled: [webBrowser canGoBack]];
    [mForwardButton setEnabled: [webBrowser canGoForward]];
}

Note that the buttons are enabled and disabled according to whether the are back or forward pages from your current position.

That's it! You will now be able to browse backward and forward, and the buttons will automatically show or be disabled as appopriate.

查看更多
Ridiculous、
3楼-- · 2019-07-25 07:56

This method will be call when webview load a request:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

Save this request to a stack. This stack is Webview's History.

Hope that help :)

查看更多
登录 后发表回答