Rectangle 27 0

xcode Mac Programming Question: How do I detect the URL of a redirect in a WebView?


- (NSURLRequest *)webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)dataSource {
    NSURLRequest *request = redirectResponse;
    //make any changes to and return new request
    return request;
}
- (void)webView:(WebView *)webView didReceiveServerRedirectForProvisionalLoadForFrame:(WebFrame *)frame {
    NSLog(@"%@",[[[[frame provisionalDataSource] request] URL] absoluteString]);
}
WebFrameLoadDelegate
WebPolicyDelegate
WebResourceLoadDelegate
webView:decidePolicyForNavigationAction:
webView:didReceiveServerRedirectForProvisionalLoadForFrame:
webView:resource:willSendRequest:redirectResponse:fromDataSource:

Whichever way you do it, make sure you set the proper delegate on the webView in order to get the methods called.

Note
Rectangle 27 0

xcode Mac Programming Question: How do I detect the URL of a redirect in a WebView?


- (void)webView:(WebView *)sender willPerformClientRedirectToURL:(NSURL *)URL delay:(NSTimeInterval)seconds fireDate:(NSDate *)date forFrame:(WebFrame *)frame
[webView setFrameLoadDelegate:object];

According to the WebView reference class in the Apple documentation, you have to set a delegate that conforms to the webframeloaddelegate protocol.

Then in object, you have to set this method:

You're a lucky guy. I've come accross the same problem an hour ago.

Note