在iBooks中打开PDF

时间:2013-01-30 20:24:39

标签: iphone objective-c ibooks

我在我的代码文件中放了一个pdf。我希望它在iBooks中打开,同时研究我发现了这个:

NSString *stringURL = @"itms-books:";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

NSString *stringURL = @"itms-bookss:";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

如何在iBook中使用此或其他方式打开PDF文件? 此致

3 个答案:

答案 0 :(得分:3)

可能为时已晚,但我创建了一个小例子,其中使用了andycodes中解释的方法。我上传到Github你可以在这里下载:

https://github.com/cjimenezpacho/openpdfibooks

基本上是IBAction中的这段代码和所需的委托方法:

NSURL *url = [[NSBundle mainBundle]
URLForResource: @"iPhoneintro" withExtension:@"pdf"];
self.docController = [UIDocumentInteractionController interactionControllerWithURL:url];
self.docController.delegate = self;
[self.docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];

Apple文档的链接:

类别: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDocumentInteractionController_class/Reference/Reference.html

答案 1 :(得分:0)

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"itms-bookss://%@",self.pathToFile]]]; 

这确实打开了本地pdf到Ibooks需要2 s。

编辑:具体到此将打开本地PDF,如果它已在设备本地的iBooks中。

如果你需要将它添加到iBooks,我知道你需要使用UIDocumentInteractionController。

答案 2 :(得分:-1)

看看这篇Tumblr帖子,解释如何使用UIDocumentInteractionController来获得类似的结果。

http://andycodes.tumblr.com/post/738375724/ios4-sdk-opening-pdfs-in-ibooks