Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 5 UIWebview Delegate: WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction

Tags:

ios

uiwebview

I am using the delegate method shouldStartLoadWithRequest to catch link clicks and handle specific cases inside my app instead of allowing the webView to navigate to the link. In this code, I am attempting to push a new ViewController onto the stack. Immediately after the attempt to push the view, I get a crash with the following message in my console:

WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate:

My code looks like this:

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    if(decision logic){
        MyViewController *vc = [[MyViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
        [vc release];
        return NO;
    }

    return YES;
}

I have also tried using a modal instead of pushing a new viewController. I get the same result. Is there any other scenarios I should be handling here?

**Edit: Just thought of this. The view I'm trying to push contains another UIWebView. Should I be doing something to the first webView before transitioning? I just testing pushing a different view controller that doesn't contain a webView and it worked fine.

like image 874
Mark Struzinski Avatar asked Oct 25 '11 01:10

Mark Struzinski


2 Answers

I fixed this by ensuring that all previous requests on the webview were stopped before continuing:

[webview stopLoading];
like image 188
Mark Struzinski Avatar answered Sep 30 '22 00:09

Mark Struzinski


I have absolutely no idea why I'm getting this error from Webkit, but I traced it down to trying to insert a value in a dictionary with a nil key.

like image 39
olivaresF Avatar answered Sep 30 '22 00:09

olivaresF