iOS UIDocumentInteractionController 第三方開啟詳解

來源:互聯網
上載者:User

 
////  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


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.