iOS Open Document with External App from UIWebVIew

无人久伴 提交于 2019-12-04 13:00:06

In [UIWebViewDelegate webView: shouldStartLoadWithRequest: navigationType: navigationType:] you can check if the URL looks like it points to a document. The simplest way to do that is just to look for pdf, doc etc. If you want it to be nicer, then use UTTypes.

NSURL* possibleDocumentURL = [request mainDocumentURL];
NSString* extension = [[possibleDocumentURL lastPathComponent] pathExtension];
// TODO: check ending

If it's a URL to a document, then just download the document. You can now either open a DocumentPreviewController, UIDocumentInteractionController or QLPreviewController. The user will still need to select where the file should go.

If the app you want to open it in supports a custom URL scheme you could pass the URL or the file itself directly to it without user interaction.

UIDocumentInteractionController will work for you.

Apple docs

Great step by step tutorial

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