Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add "Open in iBooks" to UIWebView

Tags:

ios

uiwebview

I am developing a wrapper application for a site. Basically, it opens mobile version of a site in UIWebView. Some links on the site point to PDFs.

When the same site is opened in Safari and a link to PDF is tapped a nice black stripe with "Open in iBooks" is shown over the PDF. Like on the picture below:

enter image description here

How could I implement the same looking stripe in my app?

EDIT:

I am not asking about how to create a black button on translucent background.

I am interested in reproducing the whole workflow:

  • User navigates to a PDF
  • A stripe (view) popups if and only if there is iBooks app (or any other PDF viewer) installed.
  • Tapping a button in popup transfers document to that app and the app opens.
like image 602
Bobrovsky Avatar asked Nov 14 '12 08:11

Bobrovsky


1 Answers

To check if iBooks is installed you can call:

BOOL iBooksInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"ibooks://"]];

You can present a list of of applications (why limit to iBooks only? ;) ) using:

//use the UIDocInteractionController API to get list of devices that support the file type
NSURL *pdfURL = // your pdf link.
UIDocumentInteractionController *docController = [UIDocumentInteractionController interactionControllerWithURL:pdfURL];

//present a drop down list of the apps that support the file type, click an item in the list will open that app while passing in the file.
 [docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];

Note that this doesn't work on the iOS Simulator unless you made an app that reads PDFs!

If you really want to only give the option to let the PDF to be opened in iBooks, you might want to try appending the file's URL to the @"ibooks://" scheme or the one of the other two schemes that iBooks provide (which work for books in the iBook Store but I'm not sure if it also works for other URLs) which are @"itms-books://" and @"itms-bookss://". You can then do something like:

NSURL *iBooksURLScheme = [NSURL URLWithString:@"ibooks://"];
NSString *fileURLString = // your file URL as *string*
NSURL *finalURL = [iBooksURLScheme URLByAppendingPathComponent:fileURLString];

[[UIApplication sharedApplication] openURL:finalURL];
like image 55
Gianluca Tranchedone Avatar answered Oct 21 '22 10:10

Gianluca Tranchedone