Why Is Uiwebview Cangoback=No in iOS7

Why is UIWebView canGoBack=NO in iOS7?

This seems to be related to HTML5's "Application Cache" functionality. On first launch, the site isn't cached and the UIWebView correctly detects if it can go forward or back. As soon as the cache is populated, new UIWebView instances decide that, even if the URL changes (which can be observed in UIWebViewDelegate's webView:shouldStartLoadWithRequest:navigationType:), going forward or back is not possible anymore. canGoForward and canGoBack will return NO and goForward and goBack won't do anything. This persists across restarts of the app, as long as the HTML5 cache for this specific site exists.

Maybe this problem is limited to web apps that modify the URL's Fragment identifier after the hashmark via JavaScript.
And yes, the UIWebView's behavior in this situation DID change between iOS 6 and iOS 7.

I haven't found a solution yet, and we'll probably have to wait for Apple to fix this in iOS 7.1 or so.

Edit

Other people have this problem, too:

If you are using Application Cache and also managing
states through hash or other technique, the history object will not
keep your navigation history, therefore history.back() will never work
and history.length stays in 1 forever.

(from http://www.mobilexweb.com/blog/safari-ios7-html5-problems-apis-review)

Edit 2

This problem exists in Safari 7.0 (9537.71, default in OS X 10.9 Mavericks), too. However, the most recent WebKit nightly build (r158339) seems to work correctly. It's most likely only a matter of time until the fix makes it to an iOS and OS X release.

Edit 3

This problem still exists in iOS 7.1 and and OS X 10.9.2.

Edit 4

This bug has been fixed in iOS 8 and Safari 7.1 (9537.85.10.17.1) for OS X!

Related:

  • history object doesn't keep navigation history ios7 safari

iOS - problems with canGoForward and canGoBack in webViewDidStartLoad

I solved this issue in putting the button setting code not only in webViewDidStartLoad. Write a method and call it from webViewDidStartLoad, webViewDidFinishLoad and shouldStartLoadWithRequest. Works flawlessly with my app.

UIWebView in IOS 7 doesn't handle well with Twitter/Facebook like sites (goBack/Forward not working)

This looks like the same issue I had, and here is the answer I came up with: iOS 7 UIWebView 304 cache bug, blank pages

Look for my answer there. I talk about reconstructing the request so that it 'force breaks' the UIWebView's internal cache so we can get a non-cached request (new request).

Back/Forward buttons for UIWebView - canGoBack not working with ajax sites

Managed to cobble a solution together using webView:shouldStartLoadWithRequest:navigationType:

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

I enable the back button at this point. Seems to work ok.

Disable Back and Forward button on UIToolBar in UIWebview

Send the following message to the button object to enable/disable:

// Enable 
[myButton setEnabled:YES];

// Disable
[myButton setEnabled:NO];

To determine whether you should show these buttons you should check the following properties on the webview:

[myWebView canGoBack];
[myWebView canGoForward];

You'll want to check these whenever the user loads a page. To do so implement the UIWebViewDelegate method webViewDidFinishLoad:

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
// Enable or disable back
[myBackButton setEnabled:[myWebView canGoBack]];

// Enable or disable forward
[myForwardButton setEnabled:[myWebView canGoForward]];

}

How to hide uiwebview navigation buttons

Check here: Why is UIWebView canGoBack=NO in iOS7?

You can enable/disable your navigation buttons in the shouldStartLoadWithRequest method with canGoBack and canGoForward methods on UIWebView:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
{
if ([webView canGoBack])
{
[_browserBackItem setEnabled:YES];
}
else
{
[_browserBackItem setEnabled:NO];
}
if ([webView canGoForward])
{
[_browserForwardItem setEnabled:YES];
}
else
{
[_browserForwardItem setEnabled:NO];
}
return YES;
}

Back Button on UIWebView

actionSheet:clickedButtonAtIndex: is for UIActionSheet objects, not UIButton actions.

You should probably write an IBAction method that looks something like this:

- (IBAction)backButtonTapped:(id)sender {
[_viewWeb goBack];
}

and connect it to the Touch Up Inside action from the button.

You can search for more info on IBAction but that's likely what you want



Related Topics



Leave a reply



Submit