I had the same problem. I tried to manage the story, but it is error prone. Now I have found a better solution to this.
What you want to do is simply add loadRequest roughly: blank and do it as a placeholder for you before you call loadHTMLString / loadData. Then you are completely free from monitoring history. Webview.canGoBack and canGoForward will work. Of course, you will need to hack the handle to return to the placeholder: empty. You can do this in webViewDidFinishLoad. Here is the code:
In a function when calling loadHTMLString:
[weakSelf.fbWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]]; [weakSelf.fbWebView loadHTMLString:stringResponse baseURL:url];
Code to handle goBack:
- (void)webViewDidFinishLoad:(UIWebView *)webView { if ([webView.request.URL.absoluteString isEqualToString:@"about:blank"] && ![webView canGoBack] && [webView canGoForward]) { [weakSelf.fbWebView loadHTMLString:stringResponse baseURL:url]; } }
I think it is also possible to expand this solution to handle these loadHTMLString, which are not the first load. Just having a Stack to write the entire line response and paste about: blank on each loadHTMLString. And put the stack each time back to roughly: empty.
source share