简体   繁体   English

使用捆绑包中的PDF文件从我的应用程序中打开iBooks

[英]open iBooks from my app with my PDF file from my bundle

It is continuation of open iBooks from my app I did try https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDocumentInteractionController_class/Reference/Reference.html but it is hard to understand with out code sample. 这是我尝试打开 https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDocumentInteractionController_class/Reference/Reference.html的 应用程序打开的iBooks的延续,但是很难用示例代码来理解。

I have iPhone app, that have Web View. 我有iPhone应用程序,有Web View。
After starting the app Web View opens custom PDF, and this is working fine. 启动该应用程序后,Web View将打开自定义PDF,并且工作正常。
User wil not read that PDF from my app, so I wont to add button that will open that PDF in iBooks (because iBooks have search and lost of other features…). 用户不会从我的应用程序中读取该PDF,因此我不会添加将在iBooks中打开该PDF的按钮(因为iBooks已搜索并失去了其他功能……)。
I have Toolbar on bottom with button for opening my PDF in iBooks. 我在底部的工具栏上有用于在iBooks中打开PDF的按钮。
And this is my problem, I do not have code for opening my PDF in iBooks. 这是我的问题,我没有在iBooks中打开PDF的代码。

ViewControler.h ViewControler.h

#import <UIKit/UIKit.h>

@interface BG_ViewController : UIViewController
{
    IBOutlet UIWebView *myWebView;
}

- (IBAction)openInIBooks:(id)sender;

@end

ViewControler.m ViewControler.m

#import "BG_ViewController.h"

@interface BG_ViewController ()

@end

@implementation BG_ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSString *path = [[NSBundle mainBundle] pathForResource:@"MyBOOK" ofType:@"pdf"];
    NSURL *targetURL = [NSURL fileURLWithPath:path];
    NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
    [myWebView loadRequest:request];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)openInIBooks:(id)sender
{
    NSLog(@"Clicked\n");

    // CODE ???
}

@end

What code need to be added to - (IBAction)openInIBooks:(id)sender so that it will open MyBOOK.pdf ??? 哪些代码需要添加到-(IBAction)openInIBooks:(id)sender,以便打开MyBOOK.pdf?

Best that I have is: 我最好的是:

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

But this will just open iBooks app, but with out MyBOOK.pdf. 但这只会打开iBooks应用,而没有MyBOOK.pdf。
I tried just to add "itms-books:MyBOOK.pdf", but it is not working :-( 我试图仅添加“ itms-books:MyBOOK.pdf”,但是它不起作用:-(

You can open iBooks app from your code by calling [NSURL URLWithString:@"ibooks://"]. 您可以通过调用[NSURL URLWithString:@“ ibooks://”]从代码中打开iBooks应用。 But If you want to pass document you should have a look on UIDocumentInteractionController this is a way Apple wants you do do that. 但是,如果要传递文档,则应查看UIDocumentInteractionController,这是Apple希望您执行的一种方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM