Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDFDocument does not use custom URL protocol

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.

like image 675
diederikh Avatar asked Nov 30 '12 10:11

diederikh


1 Answers

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.

like image 179
Dad Avatar answered Nov 15 '22 06:11

Dad