If have initialized an PDFDocument with an URL and assigned it to a PDFView:
view.document = [[[PDFDocument alloc] initWithURL: url] autorelease];
The URL is a file URL. I want to overwrite the URL loading with a custom NSURLProtocol to support a custom decryption system. I want to use file URL (as opposed to loading NSData redirectly) because the PDF's can contain links to other PDF's and loading without a URL will not support this.
I have registered a custom URL protocol in the app delegate:
[NSURLProtocol registerClass: [MYURLProtocol class]];
But the +canInitWithRequest:
is never called. I have tried with other (custom) schema but they give the same results.
When loading a WebView from a file URL the same +canInitWithRequest: does get called.
the NSURLProtocol class documentation makes it sound to me like NSURLProtocol subclasses are only used when loading NSURLs via NSURLConnection (or NSURLDownload):
An application should never need to directly instantiate an NSURLProtocol subclass. The instance of the appropriate NSURLProtocol subclass for an NSURLRequest is created by NSURLConnection when a download is started.
So that might be the root cause of the issue you are having. Be interesting grab the file via an NSURLConnection & associated NSURLRequest and see if your NSURLProtocol subclass is called as you expect; I suspect it will be.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With