如何使用文档的文件类型启动带有文档的 iPhone 应用程序?
在此主题中,我们学习如何关联MIME 类型和文件后缀与您的 iPhone 应用程序相关,因此当有人尝试打开该类型的文档时,您的应用程序将被调用。伟大的。
我想知道如何从另一个应用程序调用这个魔法:给定一个具有已知 MIME 类型的文档,我如何要求 iOS“启动任何接受此文档的应用程序”?
请注意,我说的是“文档”,而不是“URL”...我尝试使用指向相关文档的 HTTP URL 调用 UIApplication.openURL()
(该文档位于为其提供服务的 Web 服务器上)与正确的 MIME 类型),iPhone(在本例中实际上是运行 3.2 的 iPad)启动 Safari,它会下载文档,查看 MIME 类型,然后向您显示文档的图标和一个按钮,上面写着“在 [中打开”其他应用程序]”。这可行,但很丑陋,并且需要额外的、看似不必要的 Safari 浏览。
如果我自己手动下载文档,请将其存储在临时文件中(具有“其他应用程序”应识别的适当文件后缀),然后使用文件的file://
URL,这根本就失败了。
In this thread we learn how to associate MIME types and file suffixes with your iPhone app so your app will be invoked when someone tries to open a document of that type. Great.
I'm wondering how to invoke this magic from another app: given a document with a known MIME type, how do I ask iOS to "launch whatever app accepts this document"?
Note, I said "document", not "URL"... I tried invoking UIApplication.openURL()
with an HTTP URL pointing to the document in question (which lives on a web server that serves it up with the correct MIME type), the iPhone (actually iPad running 3.2 in this case) launches Safari, which downloads the document, looks at the MIME type, and then shows you an icon for the document and a button saying "Open in [Other App]". This works but is ugly and requires an extra and seemingly unnecessary hop through Safari.
If I download the document manually myself, store it in a temporary file (with the appropriate file suffix that should be recognized by the "Other App"), and then invoke UIApplication.openURL()
using the file's file://
URL, that simply fails.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看一下 UIDocumentInteractionController。
iPad 的示例:
https://developer.apple.com/library/ios/#documentation/General/Conceptual/iPadProgrammingGuide/CoreApplication/CoreApplication.html#//apple_ref/doc/uid/TP40009370-CH6- SW12
(稍微向上滚动到“预览和打开文件” - 该锚点将页面滚动得太远)
Take a look at UIDocumentInteractionController.
Example here for iPad:
https://developer.apple.com/library/ios/#documentation/General/Conceptual/iPadProgrammingGuide/CoreApplication/CoreApplication.html#//apple_ref/doc/uid/TP40009370-CH6-SW12
(scroll up slightly to "Previewing and Opening Files" - that anchor scrolls the page too far)