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

旧时模样 提交于 2019-12-21 06:39:55

问题


Is it possible to open a pdf file from an app itself into iBooks.

OR

any 3rd party solutions, that can use any pdf file and create a flip book thing in an app itself.


回答1:


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



来源:https://stackoverflow.com/questions/8428352/an-app-to-open-ibook-and-then-this-particular-pdf-pub-file-straightaway-in-one-g

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