Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>See <a href="http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/URLLoadingSystem/Articles/RequestChanges.html" rel="nofollow">here</a> for details on <code>connection:willSendRequest:redirectResponse:</code></p> <p>UPDATED: sorry, I breezed right over the fact that this is a Mac app not an iPhone app. Limited experience with the former; however, I believe that the same concepts apply, just instantiated differently. </p> <p>Looking at the documentation, it looks like you want <code>webView:resource:willSendRequest:redirectResponse:fromDataSource</code> (see <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/WebKit/Protocols/WebResourceLoadDelegate_Protocol/Reference/Reference.html" rel="nofollow">here</a> for details). You'll also need to set <code>webberAppDelegate</code>'s <code>resourceLoadDelegate</code> to <code>self</code>.</p> <p>UPDATED: okay, here's a bit more detail on the process. You need to understand a bit about how <a href="http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/objectivec/Chapters/ocProtocols.html#//apple_ref/doc/uid/TP30001163-CH15-SW1" rel="nofollow">protocols</a> and <a href="http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/CommunicateWithObjects.html#//apple_ref/doc/uid/TP40002974-CH7-SW18" rel="nofollow">delegates</a> work in Objective-C. Read that material in support of what follows.</p> <p>Protocols function like interfaces in Java or C#, or abstract functions in C++. They are basically a form of contract. They are mandatory by default but can be marked explicitly as @optional, meaning the compiler won't choke if one is omitted. If you look at the documentation for <code>WebResourceLoadDelegate</code>, you'll see that all the methods are optional. We want just one here, the <code>webView:resource:willSendRequest:redirectResponse:fromDataSource</code> method.</p> <p>The other part of this is the concept of the delegate. Delegates function as callbacks. This involves both an object that will carry out the callback logic and an implementation of the logic (i.e., the implementation of the method from the protocol above). This can be implemented in a number of ways, but Cocoa has a more-or-less standardized way of doing it. You need to provide the implementation of the method, and you need to identify which object is going to carry out the logic. Note that <code>WebView</code> has a bunch of different delegate protocols. Adopting all or part of one of them is called <em>conforming</em> to the protocol. This is stated in code as (I am providing a skeleton of your class here):</p> <pre><code>@interface webberAppDelegate : NSObject&lt;WebResourceLoadDelegate&gt; { WebView* webview; } @end </code></pre> <p>here I'm assuming you derive from <code>NSObject</code>; substitute whatever your base class is. This lets the compiler know to expect that you'll provide implementations of the mandatory methods as well as whichever optional methods you require. It will complain if you do not implement the mandatory methods.</p> <p>The more critical piece is to establish that the <code>Webview</code> ivar has a delegate that is going to provide implementations for one or all of methods declared by <code>WebResourceLoadDelegate</code>. You have a property for this ivar -- <code>webview</code>. Somewhere (e.g., in the viewDidLoad -- that's where I'd do it in iOS) you need to declare:</p> <pre><code>webview.resourceLoadDelegate = self; </code></pre> <p>assuming you want the callback handled by <code>webberAppDelegate</code>. Then in <code>webberAppDelegate</code>'s implementation you need to provide the definition for the method <code>webView:resource:willSendRequest:redirectResponse:fromDataSource</code>:</p> <pre><code>-(NSURLRequest*) webView:(WebView*)webview resource:(id)sender willSendRequest:(NSURLRequest*)request redirectResponse:(NSURLResponse*)redirectresponse fromDataSource:(WebDataSource*)dataSource { NSLog(@"willSendRequest delegate method called"); } </code></pre> <p>If you implement this much, you should see the log statement echoed in the console when you run your application. It's in that method that you need to handle the redirect. As I said before, I'm not well versed in the implementation of this protocol. According to <a href="http://lists.apple.com/archives/webkitsdk-dev/2009/Dec/msg00019.html" rel="nofollow">this</a> thread, it may actually be the <code>WebPolicyDelegate</code> protocol that you want. The principles involved will be the same.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload