问题
I'm using the following code attached to a button, to attempt to open a PDF file in iBooks, but nothing's happening when I click the button. The method's definitely being called.
- (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];
}
I've declared the class itself as the relevant delegate, and since the documentation says there are no required delegate methods, that's all I've done. Nothing's happening when I tap the button, and I'm trying to figure out what I'm missing – any help is greatly appreciated!
回答1:
If MS.pdf is in your bundle then you need to get the full path like so:
NSString *path = [[NSBundle mainBundle] pathForResource:@"MS" ofType:@"pdf"];
NSURL *url = [NSURL fileURLWithPath:path];
来源:https://stackoverflow.com/questions/9650263/send-bundled-pdf-to-ibooks-from-within-app