从应用内发送捆绑PDF到iBooks

我正在使用下面的代码附加到button,试图打开一个PDF文件在iBooks,但没有任何事情发生时,我点击button。 该方法肯定被称为。

- (IBAction)openDocs { NSURL *url = [NSURL fileURLWithPath:@"MS.pdf"]; UIDocumentInteractionController *docController = [[UIDocumentInteractionController alloc] init]; docController = [UIDocumentInteractionController interactionControllerWithURL:url]; docController.delegate = self; BOOL isValid = [docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES]; } 

我已经把这个类声明为相关的委托,并且由于文档说没有必要的委托方法,这就是我所做的。 当我点击button时没有任何事情发生,我试图弄清楚我错过了什么 – 非常感谢任何帮助!

如果MS.pdf在您的包中,那么您需要获取完整path,如下所示:

 NSString *path = [[NSBundle mainBundle] pathForResource:@"MS" ofType:@"pdf"]; NSURL *url = [NSURL fileURLWithPath:path];