gpt4 book ai didi

objective-c - PDFDocument 不使用自定义 URL 协议(protocol)

转载 作者:太空狗 更新时间:2023-10-30 03:52:41 26 4
gpt4 key购买 nike

如果已经使用 URL 初始化了 PDFDocument 并将其分配给 PDFView:

view.document = [[[PDFDocument alloc] initWithURL: url] autorelease];

该 URL 是一个文件 URL。我想用自定义 NSURLProtocol 覆盖 URL 加载以支持自定义解密系统。我想使用文件 URL(而不是重定向加载 NSData),因为 PDF 可以包含指向其他 PDF 的链接,没有 URL 的加载将不支持这一点。

我已经在应用委托(delegate)中注册了自定义 URL 协议(protocol):

 [NSURLProtocol registerClass: [MYURLProtocol class]];

但是 +canInitWithRequest: 永远不会被调用。我尝试过其他(自定义)架构,但它们给出了相同的结果。

当从文件 URL 加载 WebView 时,同样的 +canInitWithRequest: 会被调用。

最佳答案

NSURLProtocol class documentation在我看来,NSURLProtocol 子类仅在通过 NSURLConnection(或 NSURLDownload)加载 NSURL 时使用:

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.

所以这可能是您遇到问题的根本原因。有趣的是,通过 NSURLConnection 和关联的 NSURLRequest 获取文件,并查看您的 NSURLProtocol 子类是否如您预期的那样被调用;我怀疑会是这样。

关于objective-c - PDFDocument 不使用自定义 URL 协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13643542/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com