Send bundled PDF to iBooks from within app

2019-08-07 05:40发布

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条回答
冷血范
2楼-- · 2019-08-07 06:16

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];
查看更多
登录 后发表回答