您的位置:首页 > 产品设计 > UI/UE

iOS UIDocumentInteractionController 第三方打开详解

2016-03-27 14:57 681 查看
////  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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: