开发者

Open Local PDF in Safari in iOS

Let's say that myURL pointed to a PDF which was obtained by doing:

myURL = [[NSBundle mainBundle] URLForResource:@"my" w开发者_如何学编程ithExtension:@"PDF"];

I can call [[UIApplication sharedApplication] canOpenURL:myURL] and see that it returns YES.

However, when I call [[UIApplication sharedApplication] openURL:myURL], nothing happens and it returns NO.

Is there a way to have this work?

Yes, I know I could use a UIWebView to have it open the PDF, but in this instance, I need the Safari App to open it, if possible. I am aware the natural consequence of this will be for it to exit my application. This behavior would be acceptable in this case.

Thank you.


This is not currently possible.


As far as I know it is not possible to hand a local PDF file off to MobileSafari.

But you can easily hand off a local PDF file to any locally installed application that acts as a PDF viewer. i.e., iBooks, GoodReader, etc. If this is sufficient, you should take a look at UIDocumentInteractionController. It will present a menu of apps, and let the user choose one to open the file in. Unfortunately, Safari itself does not register as a PDF viewer.

(If you did decide to present PDFs yourself, the QLPreviewController will display the file and give you the "send to other app" functionality.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜