UIDocumentInteractionController:发送到实例的无法识别的选择器
问题描述:
我正在使用UIDocumentInteractionController
与其他应用程序共享文档(PDF)。UIDocumentInteractionController:发送到实例的无法识别的选择器
与不同应用程序的视图显示得很好,但当我按任何应用程序打开/保存/共享文件时,我的应用程序崩溃。
我得到了Unrecognised selector sent to instance
错误。
看来这个错误来自文件的URL我给(不知道寿):
[UIDocumentInteractionController interactionControllerWithURL:url];
DocumentInteractionManager.h:
@interface DocumentInteractionManager : UIViewController <UIDocumentInteractionControllerDelegate>
@property (nonatomic, retain) UIDocumentInteractionController* documentInteractionController;
@property (nonatomic, copy) NSURL *url;
- (void)openDocumentFromRect:(UIView*)view withURL:(NSURL*)fileUrl;
@end
DocumentInteractionManager.m:
@implementation DocumentInteractionManager
@synthesize documentInteractionController;
@synthesize url;
//fileUrl is something like: file:///var/mobile/Containers/Data/Application/[APP]/Library/file.pdf
- (void)openDocumentFromRect:(UIView*)view withURL:(NSURL*)fileUrl {
self.url = fileUrl;
if (url) {
documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:self.url];
// Configure Document Interaction Controller
[documentInteractionController setDelegate:self];
CGRect rect = [view frame];
[documentInteractionController presentOptionsMenuFromRect:[view frame] inView:view animated:YES];
}
}
@end
编辑:
这里是我正在创建的网址:[NSURL fileURLWithPath:pdfPath]
注意,它的工作原理,当我使用UIActivityViewController
和共享通过空投
EDIT2:
这里有一些我得到的不同消息(取决于我选择的应用程序):
-
周
- 的iBooks:
[__NSCFString URL]: unrecognized selector sent to instance
- 复制:[OS_dispatch_queue URL]:无法识别的选择发送到实例
- 电子邮件:[NSISLinearExpression URL]:无法识别的选择发送到实例
什么想法?
答
好吧,我已经想通了。
我做错了什么是我在- (void)openDocumentFromRect:(UIView*)view withURL:(NSURL*)fileUrl
方法中实例化UIDocumentInteractionController
。所以基本上当我退出该方法UIDocumentInteractionController
被摧毁。
我现在在init方法中实例化了UIDocumentInteractionController
,并且它按预期工作。
显示整个错误消息,特别是无法识别的选择器名称。 – Larme
@Larme其实,它会根据我想要使用的应用而变化。 在iBooks上:[[__NSCFString URL]:在Drpobox上发送给实例的无法识别的选择器:'[NSISEngine URL]:无法识别的选择器发送到实例' – Moucheg