2012-09-25 76 views
-2

我的應用程序創建一個PDF,可以在常規menü打開,然後查看,但不是在應用程序。如何以編程方式在ipad reader中打開pdf?打開外部PDF閱讀器

回答

2

您必須設置委託在頭的視圖控制器:

@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]; 
+0

謝謝卡洛斯。那就是我的意思。對不起,我的英語不好:-) – Jorgo

+0

Jorgo沒問題。你可以檢查我的答案爲接受的答案:) –