2015-10-07 117 views
0

我正在使用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]:無法識別的選擇發送到實例

什麼想法?

+0

顯示整個錯誤消息,特別是無法識別的選擇器名稱。 – Larme

+0

@Larme其實,它會根據我想要使用的應用而變化。 在iBooks上:[[__NSCFString URL]:在Drpobox上發送給實例的無法識別的選擇器:'[NSISEngine URL]:無法識別的選擇器發送到實例' – Moucheg

回答

0

好吧,我已經想通了。

我做錯了什麼是我在- (void)openDocumentFromRect:(UIView*)view withURL:(NSURL*)fileUrl方法中實例化UIDocumentInteractionController。所以基本上當我退出該方法UIDocumentInteractionController被摧毀。

我現在在init方法中實例化了UIDocumentInteractionController,並且它按預期工作。

相關問題