iOS - PDF Loaded in UIWebView then save to iBooks using UIDocumentInteractionController

六月ゝ 毕业季﹏ 提交于 2019-12-08 12:01:51

问题


I am loading a PDF from the web using a UIWebView, which works great and lets me interact with the PDF how I want.

Next I would like to be able to save that PDF to iBooks, so I am using a UIDocumentInteractionController. In reading the docs it seems that you can only use UIDocumentInteractionController with local files rather than a remote file like I have.

My question is, that PDF that UIWebView loads must be cached somewhere, so I really have to do another call to download that same file, just to have UIDocumentInteractionController be able to load it as a local file? Or can I somehow use that same file that UIWebView has already loaded?


回答1:


You can't directly access the data that the UIWebView caches. If you only want to download the PDF once (which is the right way to do it), save the file locally yourself. Then load it in your UIWebView like so:

NSURL* url = [NSURL URLWithString:@"path to local file"];
NSURLRequest* urlRequest = [[NSURLRequest alloc] initWithURL:url];
[myWebView loadRequest:urlRequest];
[urlRequest release];


来源:https://stackoverflow.com/questions/5330161/ios-pdf-loaded-in-uiwebview-then-save-to-ibooks-using-uidocumentinteractioncon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!