UIDocumentInteractionController:发送到实例的无法识别的选择器
UIDocumentInteractionController: unrecognized selector sent to instance
我正在使用 UIDocumentInteractionController
与其他应用共享文档 (PDF)。
带有不同应用程序的视图显示得很好,但是当我按任何应用程序来 open/save/share 文件时,我的应用程序崩溃了。
我收到 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
编辑:
这是我创建 url 的方式:[NSURL fileURLWithPath:pdfPath]
请注意,当我使用 UIActivityViewController
并通过 AirDrop
共享时它有效
编辑2:
以下是我收到的一些不同消息(取决于我选择的应用程序):
- 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
,瞧,它按预期工作。
我正在使用 UIDocumentInteractionController
与其他应用共享文档 (PDF)。
带有不同应用程序的视图显示得很好,但是当我按任何应用程序来 open/save/share 文件时,我的应用程序崩溃了。
我收到 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
编辑:
这是我创建 url 的方式:[NSURL fileURLWithPath:pdfPath]
请注意,当我使用 UIActivityViewController
并通过 AirDrop
编辑2:
以下是我收到的一些不同消息(取决于我选择的应用程序):
- 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
,瞧,它按预期工作。