UIDocumentInterRactionController 使用时的注意事项(其它应用打开)

<code class="language-iOS hljs objectivec">1、首先要遵循UIDocumentInteractionControllerDelegate
02.  
03. 2、其次是创建一个UIDocumentInteractionController对象
04. @property(nonatomic,retain)UIDocumentInteractionController *docController;
05.  
06. 3、在方法中进行UIDocumentInteractionController对象的初始化
07.  
08. - (void)open{
09. NSString *fileName = [self.listDicobjectForKey:@"fileName"];
10.  
11. NSString* path = [NSHomeDirectory()stringByAppendingPathComponent:
12.  
13. _docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:path]];//为该对象初始化一个加载路径
14.  
15. _docController.delegate =self;//设置代理
16.  
17. //直接显示预览
18. //    [_docController presentPreviewAnimated:YES];
19.  
20. CGRect navRect =self.navigationController.navigationBar.frame;
21. navRect.size =CGSizeMake(1500.0f,40.0f);
22.  
23. //显示包含预览的菜单项
24. [_docController presentOptionsMenuFromRect:navRectinView:self.viewanimated:YES];
25.  
26. //显示不包含预览菜单项
27. //[docController presentOpenInMenuFromRect:navRect inView:self.view animated:YES];
28. }
29. 4、代理方法
30.  
31. - (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
32. {
33. return self;
34. }
35.  
36. - (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller
37. {
38. return self.view;
39. }
40.  
41. - (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController *)controller
42. {
43. return  self.view.frame;
44. }</code>

使用时的注意事项

二、UIDocumentInterRactionController使用时的注意事项

1、UIDocumentInterRactionController定义的时候一定要是retain类型的,因为必须要对该对象进行持有;

2、当选择显示包含预览的菜单项 
[_docController presentOptionsMenuFromRect:navRectinView:self.viewanimated:YES];时应该注意一点,该方法会触发该类的内置打印输出,会将日志信息打印出来,从而导致App崩溃严重的可能会导致手机死机,现在还未找到解决方法。类似输出结果如下(此处省略该输出的后面部分内容,因为太多了):

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值