How to add browser history in UIWebView?

208 Views Asked by At

In safari or any browser when we press the back button, the previous page opens. But when we hold the button for a while, the browser history opens up. How do we code this in xcode?

1

There are 1 best solutions below

0
Shams Ahmed On

A view controller for this purpose is not available out of the box but is really easy to achieve. first thing you need to do is create a data container of of all websites your browser has visited using either with a NSMutableArray or a pList saved within your user document folder.

Then within your UIWebViewDelegate, webViewDidStartLoad get called each time the page has finished loading. Use the webView object to get the URL and then save to the data container:

webView.request.URL.absoluteString; // save string  

Am assuming you have a button control to go back and forward, add a UILongPressGestureRecognizer object which listens for long presses on a button. Once this has been triggered create a UITableViewController and push that on to the stack with pushViewController method and pass the data container of URLs.