美文网首页
iOS笔记-预览和分享文件到其他应用

iOS笔记-预览和分享文件到其他应用

作者: keelZJP | 来源:发表于2017-05-03 10:38 被阅读1150次

我们这里说的是利用UIDocumentInteractionController进行文件的预览和分享

注:file_urlshi是文件的存储路径,因为应用沙盒路径会变,所以建议获取的时候不要使用绝对路径

-(void)openFileViewController: (NSString *) file_url  {

NSURL *file_URL = [NSURL fileURLWithPath:file_url];

if (file_URL != nil) {

if (_documentController == nil) {

_documentController = [[UIDocumentInteractionController alloc] init];

_documentController = [UIDocumentInteractionController interactionControllerWithURL:file_URL];

_documentController.delegate = self;

}else {

_documentController.URL = file_URL;

}

[_documentController presentPreviewAnimated:YES];

}

}

实现UIDocumentInteractionController的三个代理方法

- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)interactionController

{

return self;

}

-(UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller{

NSLog(@"documentInteractionControllerDidEndPreview");

return self.view;

}

- (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController*)controller

{

NSLog(@"documentInteractionControllerDidDismissOpenInMenu");

return self.view.frame;

}

2,也可以用下面的方法直接调出应用分享不预览

NSString *filePath =xxxxxxxx;

self.documentController =

[UIDocumentInteractionController

interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];

self.documentController.delegate = self;

self.documentController.UTI = @"com.adobe.pdf";

[self.documentController presentOpenInMenuFromRect:CGRectZero

inView:self.view

animated:YES];

相关文章

  • iOS笔记-预览和分享文件到其他应用

    我们这里说的是利用UIDocumentInteractionController进行文件的预览和分享 注:file...

  • 多控制器-4

    笔记 PPT 1-应用沙盒 每个iOS应用都有自己的应用沙盒(应用沙盒就是文件系统目录),与其他文件系统隔离。应用...

  • 清理缓存

    每个ios应用都有自己的应用沙盒,应用沙盒就是文件系统目录,与其他应用的文件系统隔离,ios系统不允许访问其他应用...

  • iOS数据存储

    每个ios应用都有自己的应用沙盒,应用沙盒就是文件系统目录,与其他应用的文件系统隔离,ios系统不允许访问其他应用...

  • iOS-利用UIDocumentInteractionContr

    iOS提供了使用其他app预览文件的支持,这就是Document Interaction Controller。此...

  • iOS 的沙盒路径&文件操作

    每个iOS 应用都有自己的沙盒路径,应用沙盒就是文件系统目录,与其他应用的文件系统隔离,iOS应用不允许访问其他应...

  • QLPreviewController的title更改

    ios 中预览文件的方式有UIDocumentInteractionController和QLPreviewCon...

  • 沙盒

    一、iOS沙盒机制介绍(1)概念:每个ios应用都有自己的应用沙盒,应用沙盒就是文件系统目录,与其他应用放入文件 ...

  • iOS 其他应用的文件,分享到自己的APP?docx文件的iOS

    微信查看文件,右上角点击可以选择使用第三方软件打开,那么如何让微信监测到自己的APP呢,在弹出选择框的时候,让自己...

  • 一、SandBox

    每个iOS应用都有自己的应用沙盒(应用沙盒就是文件系统目录),与其他文件系统隔离。应用必须待在自己的沙盒里,其他应...

网友评论

      本文标题:iOS笔记-预览和分享文件到其他应用

      本文链接:https://www.haomeiwen.com/subject/qxjktxtx.html