UIDocumentInteractionController的使用

//
//  ViewController.m
//  pdfViewer
//
//  Created by Johnay  on 17/9/28.
//  Copyright © 2017年 Johnay. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIDocumentInteractionControllerDelegate>

@property (nonatomic, strong) UIDocumentInteractionController *document;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"pdffile" withExtension:@"pdf"];
    //    NSString *docu = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    //    NSString *filePath = [docu stringByAppendingPathComponent:@"004.png"];
    //    NSURL *url = [NSURL fileURLWithPath:filePath];
    
    
    self.document = [UIDocumentInteractionController interactionControllerWithURL:url];
    self.document.delegate = self;
    
    // 不展示可选操作
    //    [self.document presentOpenInMenuFromRect:self.view.bounds inView:self.view animated:YES];
    
    
    // 展示可选操作
    // 可结合代理方法documentInteractionControllerViewControllerForPreview:显示预览
    [self.document presentOptionsMenuFromRect:self.view.bounds inView:self.view animated:YES];
    
}

- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller {
    return self;
}
/**
 *  文件分享面板退出时调用
 */
- (void)documentInteractionControllerDidDismissOpenInMenu:(UIDocumentInteractionController *)controller {
    NSLog(@"dismiss");
}

/**
 *  文件分享面板弹出的时候调用
 */
- (void)documentInteractionControllerWillPresentOpenInMenu:(UIDocumentInteractionController *)controller {
    NSLog(@"WillPresentOpenInMenu");
    
}

/**
 *  当选择一个文件分享App的时候调用
 */
- (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(nullable NSString *)application {
    NSLog(@"begin send : %@", application);
}
@end
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 时间具有粘稠的特质,渺渺众生在偶然中能感知它脉动的速度。有时候,一秒钟可以漫长如一天;而一年也可以短得如一场...
    Icarus07阅读 3,385评论 4 2
  • 此时,还有多少人,想要成为一位作家? 就像歌者是为了表达自我,抒发灵魂之弦音,作者是用语言文字书写了自我世界的乌托...
    我的唱片机一直忘了关阅读 2,948评论 0 3
  • 一, 我转我的千湖,它们像些值得围坐的火塘我打我的水漂用捡到的狗头金和那些可以被拟人的事物。我采我心中的莲子我爱这...
    王独树阅读 2,773评论 0 1
  • linux命令行简介 小技巧 初体验: 切换到~目录(windows切换到 C 盘)在当前目录下创建文件夹 pro...
    hhg121阅读 2,806评论 0 0
  • 专题 青春散场 目录 上一章【连载】青春散场 第一章 报到入学 (1) 青春就像是一个大大的笑脸和一个大大的哭脸,...
    圆琛儿阅读 1,270评论 4 4

友情链接更多精彩内容