Re: Redirecting from a URL protocol
Christiaan Hofman <[email protected]> Fri, 8 Oct 2010 18:20:54 +0200
| Newsgroups | gmane.comp.macosx.devel |
|---|---|
| Message-ID | <[email protected]> |
On Oct 8, 2010, at 17:41, Brian Hardy wrote: > Christiaan, > > From the NSURLProtocol docs, it looks like you basically need to implement a subclass that returns YES from +canInitWithRequest: for requests that you want to handle. Then you have to call NSURLProtocol's +registerClass: method with your subclass to make it available to the URL loading system. > > I've never done this, so that's just my interpretation of the documentation. It seems that if you do those things, then the URL loading system will be responsible for calling any other methods on your NSURLProtocol implementation. > > Hope this helps. > /brian > Sure, I know that part, and I've done that. But now my question is: how do I handle the request, i.e. how do I implement startLoading, because that's the method that the URL loading system calls next? Christiaan > On Oct 8, 2010, at 11:25 AM, Christiaan Hofman wrote: > >> Hi list, >> >> I am trying to implement an NSURLProtocol subclass that should redirect certain custom URLs to some other (standard) URL, for instance to a file: URL pointing to a file inside the app bundle. It is not clear to me how to achieve this, and there is very little documentation and sample code about implementing NSURLProtocol, apart from the generic URL loading docs I could only find one sample that loads from some data rather than redirecting. And of course I tried Google and all without much success. >> >> What I seem to understand is that somehow I have to call -[NSURLProtocolClient URLProtocol:wasRedirectedToRequest:redirectResponse:] at some point, but it is not clear precisely how and where. Should I do that in -[NSURLProtocol startLoading]? In particular it is not clear what the redirectProtocol parameter should be. Also it is not clear to me whether and when I should call other client protocol methods. >> >> Could anyone help me in pointing out how to do that, perhaps pointing to some sample code? >> >> thanks, >> Christiaan >> >> _______________________________________________ >> MacOSX-dev mailing list >> [email protected] >> http://www.omnigroup.com/mailman/listinfo/macosx-dev >