Question

All right, I am having a problem opening the iBooks app using an IBAction in my app. I have it set up so that when the user presses a button, it calls this action to open the iBooks app:

-(IBAction)openBooks:(id)sender
{
    NSString *stringURL = "iBooks://";
    NSURL *url = [NSURL URLWithString:stringURL];
    [[UIApllication sharedApplication] openURL:url];
}

This does the whole app switching this and looks great. I see the bookshelf where all of my books should be, but then the iBooks app crashes before my books load! The app I wrote doesn't crash, but iBooks fails!

I am running my app via XCode (the app isn't actually distributed to my iPad, per se), is that why iBooks crashes? When I touch the iBooks icon to open it (not via my app) it opens fine and works. But if I change the url in my IBAction like this:

NSString *stringURL = "maps://";

and run my app, my button works and Maps opens up!

Is this an iBook bug? Or is it my bug?

FWIW, I'm using iOS 6 and XCode 4.6.3

Was it helpful?

Solution 2

OK, so my bad. I found that I was using the wrong URL scheme. The iBooks:// I got from wiki.akosma does NOT work, but itms-books: DOES work.

OTHER TIPS

You HAVE to check if iOS can open a url before opening it. Either your url scheme is wrong (like in your case) or the user doesn't even have iBooks installed. Even if you have the correct url you can't open it unless the user has installed an app that corresponds to the url.

NSURL *url = ...
if ([[UIApplication sharedApplication] canOpenURL:url]) {
    [[UIApplication sharedApplication] openURL:url];
}
else {
    // can't open url
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top