How to open a file on iBooks

主宰稳场 提交于 2019-12-19 11:49:21

问题


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];

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

Any tips?


回答1:


just use this

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

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

See this related question How do I launch iBooks e-reader programmatically on iPad?



来源:https://stackoverflow.com/questions/9577165/how-to-open-a-file-on-ibooks

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!