iOS UIDocumentInteractionController 第三方打开详解


//
//  ViewController.m
//  test_UIdocument_01
//
//  Created by admin on 3/27/16.
//  Copyright © 2016 jeffasd. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property (nonatomic, strong)UIButton *presentButton;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    
    _presentButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    _presentButton.frame = CGRectMake(100, 100, 200, 200);
    _presentButton.backgroundColor = [UIColor redColor];
    
    [self.view addSubview:_presentButton];
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    NSString *fileString = [[NSBundle mainBundle] pathForResource:@"ios" ofType:@"pdf"];
    
    NSURL *fileUrl = [NSURL URLWithString:fileString];
//    
    NSURL *fileUrl = [[NSBundle mainBundle] URLForResource:@"ios" withExtension:@"pdf"];
//
//    NSLog(@"the fileUrl is %@", fileUrl);
//    
//   NSURL *testFileUrl = [NSURL fileURLWithPath:fileString];
//    
//    NSLog(@"the file url is %@", testFileUrl);
//    
//    NSString *string1 = fileUrl.path;
//    
//    NSArray *array = fileUrl.pathComponents;
//    
//    NSString *string2 = fileUrl.parameterString;
    
    
    
//    [NSFileManager ];
    
    UIDocumentInteractionController *documentController = [UIDocumentInteractionController interactionControllerWithURL:fileUrl];//这样写处出现 
<p class="p1"><span class="s1"><strong>2016-03-27 14:20:08.253 test_UIdocument_01[743:44711] -[NSMachPort _openDocumentWithApplication:]: unrecognized selector sent to instance 0x170169fc0</strong></span></p><p class="p1"><span class="s1"><strong>2016-03-27 14:20:08.255 test_UIdocument_01[743:44711] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSMachPort _openDocumentWithApplication:]: unrecognized selector sent to instance 0x170169fc0'</strong></span></p><p class="p1"><span class="s1"><strong>*** First throw call stack:</strong></span></p><p class="p1"><span class="s1"><strong>(0x18673822c 0x1981a80e4 0x18673f2f4 0x18673c0a8 0x18663e96c 0x18b701a80 0x18b89a7f4 0x18b4baab0 0x18b4bcf2c 0x18b2d6db8 0x18b1ec55c 0x18b1ec0c4 0x18b1ebfcc 0x18aaf562c 0x1000bcf94 0x1000c1c28 0x1866ef544 0x1866ed5ec 0x186618f74 0x18ff3b6fc 0x18b21ad94 0x100084960 0x198852a08)</strong></span></p><p class="p1"><span class="s1"><strong>libc++abi.dylib: terminating with uncaught exception of type NSException</strong></span></p><p class="p2"><span class="s1"><strong>(lldb) </strong></span></p>这个错误 原因是:<div>
查阅了一下Apple Developer上的文档,原来,在ARC环境下展示<code>UIDocumentInteractionController</code>时,当我的函数方法调用完毕,退栈之后,<code>UIDocumentInteractionController</code>的实例就被释放掉了,展示出来的这个View由<code>Quick Look</code>框架来操作,并不会对<code>UIDocumentInteractionController</code>产生引用。当点击View上面的Button时,内部操作仍然会继续访问这个<code>UIDocumentInteractionController</code>实例,就会报出上述错误。</div>
    
//    [documentController presentOpenInMenuFromRect:self.view.bounds inView:self.view animated:YES];
    
    UIView *view = [UIView new];
    view.frame = CGRectMake(100, 200, 300, 300);
    view.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:view];
    
    [documentController presentOpenInMenuFromRect:CGRectMake(100, 200, 300, 300) inView:self.view animated:YES];
//iPhone 下面不能指定 rect 只会在底部 下面弹出,iPad 上面可以指定 弹出的 Rect 
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值