UIDocumentInteractionController浏览文件

来源:互联网 发布:mac 更改ruby路径 编辑:程序博客网 时间:2024/06/06 02:38

之前写的一个项目打开文件直接用的UIWebView,word、excel、tex等等打开很方便。这次写项目用到了UIDocumentInteractionController,这是IOS提供的使用其他程序打开你的App不支持的文件格式。

    UIDocumentInteractionController *documentInteractionController = [UIDocumentInteractionControllerinteractionControllerWithURL:[NSURLfileURLWithPath:url]];

    [documentInteractionController setDelegate:[FileOpenToolsharedInstance]];

    BOOL canShow = [documentInteractionControllerpresentPreviewAnimated:YES];

    

    if (!canShow) {

        // 无法打开的文件类型

        AppDelegate *appDelegate = (AppDelegate *)[[UIApplicationsharedApplication] delegate];

        UIViewController *rootVC = appDelegate.window.rootViewController;

        [v presentOptionsMenuFromRect:CGRectZeroinView:rootVC.viewanimated:YES];

    }

这种方法是可行的但是一开始用的时候我并没有在主线程中使用,因为是UI的变动,所以一定要在主线程中

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{

                 // Do time-consuming task in background thread

                 // Return back to main thread to update UI

                 dispatch_sync(dispatch_get_main_queue(), ^{

                     // 浏览写在这里

                 });

             });



报错信息如下:

bool _WebTryThreadLock(bool), 0x1556d49d0: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
1   0x187dd0f8c WebThreadLock
2   0x18929ea68 <redacted>
3   0x18927508c <redacted>
4   0x189274f64 <redacted>
5   0x189408f04 <redacted>
6   0x189049810 <redacted>
7   0x18905803c <redacted>
8   0x1892eb6c0 <redacted>
9   0x18905f4b4 <redacted>
10  0x18924a88c <redacted>
11  0x18936a244 <redacted>
12  0x18924a404 <redacted>
13  0x1892046cc <redacted>
14  0x18910fd28 <redacted>
15  0x18910fa04 <redacted>
16  0x18910f96c <redacted>
17  0x18904c0e4 <redacted>
18  0x1869f2a28 <redacted>
19  0x1869ed634 <redacted>
20  0x1869ed4f4 <redacted>
21  0x1869ecb24 <redacted>
22  0x1869ec86c <redacted>
23  0x186a1bc90 <redacted>
24  0x183b721e0 <redacted>
25  0x183b71d58 <redacted>
26  0x183b7153c pthread_mutex_lock
27  0x183b71020 start_wqthread


0 0
原创粉丝点击