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

匿名 (未验证) 提交于 2019-12-03 01:38:01

问题:

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.

回答1:

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

[webview stopLoading];


回答2:

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.



回答3:

Check out if you nullify delegate property of UIWebView in its controller dealloc method (of course if this controller is webview's delegate). Like this:

- (void) viewDidLoad {     webView.delegate = self; } - (void) dealloc {     webView.delegate = nil; }

From the Apple docs on the delegate property:

Important. Before releasing an instance of UIWebView for which you have set a delegate, you must first set its delegate property to nil. This can be done, for example, in your dealloc method.



回答4:

Yet another cause for this error can be the fact that Autolayout is accidentally left enabled in the viewcontroller containing the webview. This happened to me while testing on iOS5.



回答5:

The following answer to a similar question solved the issue for me:
uiwebview loading local html file - strange Webkit error



回答6:

I got a similar error:

***WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:frame:decisionListner: delegate: - [UIPopoverController dealloc] reached while popover is still visible.

The problem seems to be caused by the following code:

UIPopoverController *pc = [[UIPopoverController alloc] initWithContentViewController:vc]; [pc presentPopoverFromRect:frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];

Apparently, pc is being deallocated when the routine exits. I changed the code to make pc a property and WebKit stopped complaining.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!