Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

loading different page using webView: decidePolicyForNavigationAction: request: frame: decisionListener: method

Hii All,

I want to load a new page when following method is called....I am using the following code..



(void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id )listener
{
  [[myWebView mainFrame] loadRequest:someRequest];
}

but this method is called multiple times and my application crashes if i use [listener use] instead of loadRequest it works fine but launches the url clicked . but i want to load some other url how is it possible?

like image 571
Sid Avatar asked Oct 13 '22 20:10

Sid


2 Answers

You should simply add [listener ignore] method call.

- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id )listener
{
    [listener ignore];
    [[myWebView mainFrame] loadRequest:someRequest];
}
like image 81
Borys Verebskyi Avatar answered Nov 15 '22 12:11

Borys Verebskyi


It's called multiple times as you say, so you have to pay attention to this:
[actionInformation valueForKey: @"WebActionNavigationTypeKey"]

That value should be one of the WebNavigationType enum:
WebNavigationTypeLinkClicked,
WebNavigationTypeFormSubmitted,
WebNavigationTypeBackForward,
WebNavigationTypeReload,
WebNavigationTypeFormResubmitted,
WebNavigationTypeOther

You will get WebNavigationTypeLinkClicked first as a result of a link clicked, and here you can decide whether to load the page clicked or something else.
Immediately after you get WebNavigationTypeOther which is the page load, and you can ignore it.

like image 40
Petruza Avatar answered Nov 15 '22 13:11

Petruza