【问题标题】:How to open a file on iBooks如何在 iBooks 上打开文件
【发布时间】:2012-03-06 02:37:52
【问题描述】:

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

有什么建议吗?

【问题讨论】:

    标签: ios pdf epub ibooks


    【解决方案1】:

    就用这个

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

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

    查看这个相关问题How do I launch iBooks e-reader programmatically on iPad?

    【讨论】:

      猜你喜欢
      • 2014-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-11
      • 2013-07-22
      相关资源
      最近更新 更多