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.


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.

链接地址: http://www.djcxy.com/p/5932.html

上一篇: NSURLProtocol对视频请求失败

下一篇: PDFDocument不使用自定义URL协议