UIDocumentInteractionController是OC语言的一个类,但是他并不是一个controller,而是一个继承自NSObject类
一、主要作用:
- 预览类似pdf、doc、ppt等类型文件的类。
- 可以将用户接收到的文件分享到用户手机上的其他App中。
二、使用方式:
1.预览文件,并可以分享文件,如图1
2.直接分享文件,如图2
三、使用方法:
1.创建一个UIDocumentInteractionController类的属性:
@property (nonatomic,strong)UIDocumentInteractionController * document;
2.遵循UIDocumentInteractionControllerDelegate
@interface OpenAndShareFileViewController () <UIDocumentInteractionControllerDelegate>
3.初始化document
1.指定要分享的链接
NSURL *URL = [[NSBundle mainBundle] URLForResource:@"ios-" withExtension:@"pdf"];
_document = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:cachesDir]];
2.设置分享代理
_document.delegate = (id)self;
3.哪类文件支持第三方打开,这里不证明就代表所有文件!
// _document.UTI = @"com.microsoft.word.doc";
4.判断手机中有没有应用可以打开该文件并打开分享