How to launch an iPhone app with a document using the document's file type?
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开发者_StackOverflow 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.
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)
精彩评论