本文介绍了如何在iBooks上打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I open a book on iBooks? I tried the following code, that works, but asks the user to choose an application to open the file:

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上打开,而无需询问用户。

I want it to open directly on iBooks, without asking the user for this.

任何提示?

推荐答案

只需使用此

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

其中stringUrl是你的 filePath ,其中 itms-books:开头

Where stringUrl is your filePath, with itms-books: at the beginning

查看此相关问题

这篇关于如何在iBooks上打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-30 20:28