an app to open iBook and then this particular pdf/pub file straightaway in one go

梦想的初衷 提交于 2019-12-03 23:06:18
Mutix

You can indeed open a PDF file from an app into iBooks (or any other installed app that can read PDF files).

To do this, you can use the 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];
}

The UIDocumentInteractionController will open a popover (on iPad) or an action sheet (on iPhone) with a choice of all the PDF capable apps that are installed on the device so the user can choose his favorite one he wants to read the PDF with.

There are also a few decent PDF reader libraries you can use to open the PDF directly in your app, rather than having to switch application, one of which is VFR PDF Reader/Viewer for iOS

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