2

I want to open specific file in iBooks App. I'm using UIDocumentsIntractionController to send this file to iBooks App. My code:

class ViewController : UIViewController {
 ...
 ...
     @IBOutlet var iBooksBtn: UIButton!
     @IBAction func book(sender: AnyObject) {
         let ibookPath = NSBundle.mainBundle().pathForResource("test1",ofType: "ibooks")!
         interactionController = UIDocumentInteractionController(URL: NSURL(fileURLWithPath:ibookPath))
         interactionController.UTI = "com.apple.ibooks"
         interactionController.presentOpenInMenuFromRect(CGRectZero,inView:self.iBooksBtn, animated:false)
    }
...
...

}

So, for now i store this file in mainBundle, but in future i want to download it from the Internet. So when i press button, i got few results to choose:

enter image description here

But i want to open this file ONLY with iBooks and without requests to choose App (as on picture). As far as i know i need to use UTI for *.ibooks file, i guess UTI, that i used is wrong. Thanks for any help. Also custom URL scheme (ibooks:// and etc.) is not working for me.

pavel_s
  • 465
  • 1
  • 7
  • 27
  • The `UIDocumentsIntractionController` will show all apps that registered to handle the UTI. Thus you see copy in the sheet. There is now way to open iBooks other then using `UIDocumentsIntractionController`. Also you want to make sure that the user has iBooks installed by checking the iBooks URL scheme. – rckoenes Dec 01 '15 at 09:50
  • Hi! Have you find a solution for that? – Ne AS Nov 17 '16 at 00:15
  • Do you have any solution related to books? – Rushabh May 14 '20 at 13:21

1 Answers1

0

To open iBooks you should use custom URL scheme:

To open the library:

NSString *stringURL = @"ibooks://";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

To open the iBooks store at a particular book page, you have to add the complete URL to that particular book:

NSString *stringURL = @"itms-books://itunes.apple.com/de/book/marchen/id436945766";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

NSString *stringURL = @"itms-bookss://itunes.apple.com/de/book/marchen/id436945766";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
Oleg Gordiichuk
  • 15,240
  • 7
  • 60
  • 100
  • As i said, this scheme is not working for me. If i delete book from iBook App and then try to re-open it in my app i got nothing (iBooks App is opened, but there is no my book) – pavel_s Dec 01 '15 at 09:41