在 iOS 中的 Safari 中打开本地 PDF
假设 myURL 指向通过执行以下操作获得的 PDF:
myURL = [[NSBundle mainBundle] URLForResource:@"my" withExtension:@"PDF"];
我可以调用 [[UIApplication sharedApplication] canOpenURL:myURL] 并看到它返回 YES。
但是,当我调用 [[UIApplication sharedApplication] openURL:myURL]
时,没有任何反应,并且返回 NO。
有办法完成这项工作吗?
是的,我知道我可以使用 UIWebView 打开 PDF,但在这种情况下,如果可能的话,我需要 Safari 应用程序来打开它。我知道这样做的自然结果将是它退出我的申请。在这种情况下,这种行为是可以接受的。
谢谢。
Let's say that myURL pointed to a PDF which was obtained by doing:
myURL = [[NSBundle mainBundle] URLForResource:@"my" withExtension:@"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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
目前这是不可能的。
This is not currently possible.
据我所知,不可能将本地 PDF 文件交给 MobileSafari。
但您可以轻松地将本地 PDF 文件移交给任何本地安装的充当 PDF 查看器的应用程序。例如,iBooks、GoodReader 等。如果这足够了,您应该看看 UIDocumentInteractionController。它将显示一个应用程序菜单,并让用户选择一个来打开文件。不幸的是,Safari 本身并没有注册为 PDF 查看器。
(如果您决定自己演示 PDF,QLPreviewController 将显示该文件并为您提供“发送到其他应用程序”功能。)
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.)