一个应用程序打开iBook,然后直接打开这个特定的pdf / pub文件

时间:2011-12-08 08:48:39

标签: ios ipad ibooks

是否可以从应用程序本身打开pdf文件到iBooks。

OR

任何第三方解决方案,可以使用任何pdf文件并在应用程序本身中创建翻页书。

1 个答案:

答案 0 :(得分:0)

您确实可以从应用程序打开PDF文件到iBooks(或任何其他可以阅读PDF文件的已安装应用程序)。

为此,您可以使用UIDocumentInteractionController

NSString *pdfPath = @"path to your pdf file";
NSURL *url = [NSURL fileURLWithPath:pdfPath];
UIDocumentInteractionController *docController = [UIDocumentInteractionController interactionControllerWithURL:url];

docController.delegate = self;
[docController retain];
// docController is released when dismissed (autorelease in the delegate method)

BOOL isValid = [docController presentOpenInMenuFromRect:readPdfButton.frame inView:self.view  animated:YES];

if (!isValid) {
    NSString * messageString = [NSString stringWithFormat:@"No PDF reader was found on your device. In order to consult the %@, please download a PDF reader (eg. iBooks).", yourPDFFileTitle];

    UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:messageString delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
    [alertView release];
}

...

// UIDocumentInteractionController delegate method
- (void)documentInteractionControllerDidDismissOpenInMenu:(UIDocumentInteractionController *)controller {
     [controller autorelease];
}

UIDocumentInteractionController将打开popover(在iPad上)或操作表(在iPhone上),可选择安装在设备上的所有PDF应用程序,以便用户可以选择自己喜欢的应用程序阅读PDF文件。

您可以使用一些不错的PDF阅读器库直接在您的应用中打开PDF,而不必切换应用程序,其中一个是VFR PDF Reader/Viewer for iOS