iOS文件展示及分享(一) UIDocumentInteractionController

公司项目里有云盘功能,所以需要做文件展示和下载功能。
快速开发所以使用了系统自带的UIDocumentInteractionController
UIDocumentInteractionController 是系统提供的用来展示文件的,但是展示的文件必须是下载到本地的文件,而不能在线浏览,所以需要将文件存到本地。

NSURL *url = [NSURL fileURLWithPath:filePath];//filePath是文件保存的位置

UIDocumentInteractionController  * documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:url];

[documentInteractionController setDelegate:self];

[documentInteractionController presentPreviewAnimated:YES];//展示文件详情

//如果想直接分享到第三方APP中
//[documentInteractionController presentOpenInMenuFromRect:self.view.bounds inView:self.view animated:YES];

实现代理

#pragma mark - UIDocumentInteractionController 代理方法
//从哪个控制器打开
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller{
    return self;
}

- (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller{
    return self.view;
}

- (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController *)controller{
    return self.view.bounds;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 框架简介--主要定位于互联网企业架构,已内置企业信息化系统的基础功能和高效的代码生成工具,包括:系统权限组件、数据...
    swiftie10阅读 3,793评论 1 1
  • 一、当你到了18岁,你可能面临着两个重大的决定。 1.你将如何谋生 2.你选择一个什么样的人生伴侣 首先,如果有可...
    千言万语娟娟阅读 3,767评论 0 0
  • 今天分享一张很有名的木椅。学名:伊姆斯弯木躺椅 。作为美国最重要的现代艺术博物馆MOMA的永久收藏品,伊姆斯弯木躺...
    素心小筑阅读 2,607评论 0 1

友情链接更多精彩内容