Send bundled PDF to iBooks from within app

杀马特。学长 韩版系。学妹 提交于 2019-12-24 17:49:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!