打开外部pdf阅读器

时间:2012-09-25 10:00:18

标签: objective-c ipad

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

1 个答案:

答案 0 :(得分: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];