-2

我的应用程序创建了一个 pdf,可以在常规菜单中打开然后查看,但不能在应用程序中查看。如何在 ipad 阅读器中以编程方式打开 pdf?

4

1 回答 1

2

您必须在标头的 ViewController 中设置委托:

@interface YourViewController : UIViewController <UIDocumentInteractionControllerDelegate>

然后你必须实现这个方法:

- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
    return self;
}

然后,当您发现必须打开哪个 pdf 时:

    NSString *sPathPDF = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"name.pdf"]]; //path example for a local stored pdf
    NSURL *urlPDF = [NSURL fileURLWithPath:sPathPDF];
    UIDocumentInteractionController *dicPDF = [UIDocumentInteractionController interactionControllerWithURL: urlPDF];
    [dicPDF setDelegate:self];
    [dicPDF presentPreviewAnimated: YES];
于 2012-09-25T10:28:41.753 回答