1

如何在 iBooks 上打开一本书?我尝试了以下代码,它有效,但要求用户选择一个应用程序来打开文件:

self.docController = [UIDocumentInteractionController alloc];

//leaves only the file name
NSString *bookFile = @"my-book.pdf";

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex: 0];

NSString* filePath = [documentsDirectory stringByAppendingPathComponent: bookFile];

// Using the Book path
self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];

// setting the delegate
_docController.delegate = self;

// open the menu only if we find a valid application that can 
// open the file
BOOL isValid = [self.docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];

我希望它直接在 iBooks 上打开,而无需询问用户。

有小费吗?

4

1 回答 1

3

就用这个

NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

stringUrl 在哪里是你的filePathitms-books:在开头

请参阅此相关问题如何在 iPad 上以编程方式启动 iBooks 电子阅读器?

于 2012-05-02T15:15:01.130 回答