UIDocumentInteractionController浏览文件
2016-06-03 16:15
561 查看
之前写的一个项目打开文件直接用的UIWebView,word、excel、tex等等打开很方便。这次写项目用到了UIDocumentInteractionController,这是IOS提供的使用其他程序打开你的App不支持的文件格式。
UIDocumentInteractionController *documentInteractionController = [UIDocumentInteractionController
interactionControllerWithURL:[NSURL
fileURLWithPath:url]];
[documentInteractionController setDelegate:[FileOpenTool
sharedInstance]];
BOOL canShow = [documentInteractionController
presentPreviewAnimated:YES];
if (!canShow) {
// 无法打开的文件类型
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication
sharedApplication]
delegate];
UIViewController *rootVC = appDelegate.window.rootViewController;
[v presentOptionsMenuFromRect:CGRectZero
inView:rootVC.view
animated: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
UIDocumentInteractionController *documentInteractionController = [UIDocumentInteractionController
interactionControllerWithURL:[NSURL
fileURLWithPath:url]];
[documentInteractionController setDelegate:[FileOpenTool
sharedInstance]];
BOOL canShow = [documentInteractionController
presentPreviewAnimated:YES];
if (!canShow) {
// 无法打开的文件类型
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication
sharedApplication]
delegate];
UIViewController *rootVC = appDelegate.window.rootViewController;
[v presentOptionsMenuFromRect:CGRectZero
inView:rootVC.view
animated: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
相关文章推荐
- iOS中UICollectionView及其常用方法
- Jira和Confluence集成Crowd实现SSO-构建高效的团队协作工具
- version `GFORTRAN_1.4' not found (required by /usr/lib/liblapack.so.3) 问题的解决方案
- break与continue
- Orocos 无锁数据操作 Muliti Writer Single Reader Queue
- 完全定制UITabBarViewController
- iOS开发之UITapGestureRecognizer单双击
- 使用orm(Sequelize) 操作 MySQL (2)
- Entity Framework Code First (五)Fluent API - 配置关系
- Entity Framework Code First (四)Fluent API - 配置属性/类型
- 单元格左侧附带选择按钮
- Java中 String、StringBuffer 、StringBuilder 总结
- requireGestureRecognizerToFail 手势识别
- break,continue,break的用法与区别
- 从零开始构建MSBuild C#项目文件
- execute、executeUpdate、executeQuery三者的区别(及返回值)
- iOS在UIView获取UIViewController
- ios barTintColor backgroundColor tintColor UITextAttributeTextColor的区别
- easyui主界面布局easyui-layout用法一例
- LCD1602