如何在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上打开,而不会向用户询问。
任何提示?
答案 0 :(得分:3)
只需使用此
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
其中stringUrl是您的filePath
,开头是itms-books:
请参阅此相关问题How do I launch iBooks e-reader programmatically on iPad?