Reputation: 21
I have a iBook file (say SampleiBook.iba) within the app bundle (not in documents directory). Now i just want to open SampleiBook from within app. I tried this,
NSString *path = [[NSBundle mainBundle] pathForResource:@"SampleiBook" ofType:@".iba"];
NSString *stringURL = [@"ibooks://" stringByAppendingPathComponent:path];
NSURL *url = [NSURL URLWithString:stringURL];
if ([[UIApplication sharedApplication] canOpenURL:url])
{
NSLog(@"Yes");
}
[[UIApplication sharedApplication] openURL:url];
the iBook application gets opened, showing only the files within the iBook application. But i want the one in app bundle to be opened.
Please guide me in achieving this.
Upvotes: 0
Views: 1105
Reputation: 179
It appears that you are trying to load the .iba (iBooks Author Book) file from your app. This not going to work because .iba is the file that contains your source for the .ibooks file type that I think you really want to load.
I am writing in swift these days. Here is a swift example I just ran. Assumes that the unbutton is wired from a nib or storyboard
@IBOutlet weak var iBooksBtn: UIButton!
@IBAction func iBooksBtnPressed(sender: AnyObject)
{
let ibookPath = NSBundle.mainBundle().pathForResource("Cupertino",
ofType: "ibooks")!
let url = NSURL(fileURLWithPath: ibookPath)
let interactionController = UIDocumentInteractionController(URL:url!)
interactionController.presentOptionsMenuFromRect(CGRectZero,
inView:self.iBooksBtn, animated:false)
}
Upvotes: 1
Reputation: 69499
You will have to use the UIDocumentInteractionController
to open the iBook in iBooks.
You can easily create an instance for the iBook in mian bundle:
NSURL *iBookResourceURL = [[NSBundle mainBundle] URLForResource:@"SampleiBook" withExtension:@"iba"];
UIDocumentInteractionController *interactionController =
[UIDocumentInteractionController interactionControllerWithURL: iBookResourceURL];
Upvotes: 0