Send PDF to iBooks - iphone

Now iBooks supports PDF. My app has access to many PDF files. Is it possible to send PDFs to iBooks (or other PDF readers like GoodReader and iAnnotate PDF) from my app?

//get path to file you want to open
NSString *fileToOpen = [[NSBundle mainBundle] pathForResource:#"readme" ofType:#"pdf"];
//create NSURL to that path
NSURL *url = [NSURL fileURLWithPath:fileToOpen];
//use the UIDocInteractionController API to get list of devices that support the file type
docController = [UIDocumentInteractionController interactionControllerWithURL:url];
[docController retain];
//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.
BOOL isValid = [docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];

To answer my own question - yes, you can send a PDF to apps supporting custom URL scheme using this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
URL scheme for GoodReader is:
url=#"ghttp://www.mysite.com/myfile.pdf";
iAnnotate PDF is:
url=#"pdfs://www.mysite.com/myfile.pdf";
Does anyone know the custom URL scheme for iBooks?

Use this link to find the url schemes http://schemes.zwapp.com/
and use [[UIApplication sharedApplication] openURL:url];
to launch in that application.
thanks

Related

PDF preview like Mail App

I am looking for a PDF preview feature similar to the one available when a PDF is received via mail in iPad mail app. It has options like Print/Mail and an Open In menu. Do you have any idea is it an apple's custom implementation or part of framework. I couldn't find in QLPreviewController and UIDocInteract framework.
its very simple to implement .. you will just load NSURLRequest with the NSURL that hold the pdf path into UIWebView.
for example :
NSString *pdfPath = [[NSBundle mainBundle] pathForResource:#"iPadHIG" ofType:#"pdf"];
NSURL *pdfUrl = [NSURL fileURLWithPath:pdfPath];
[webView loadRequest:[NSURLRequest requestWithURL:pdfUrl]];
webView.scalesPageToFit = YES;

open pdf in to another pdfviewer application from my application

I have one pdf in my application and I want to open that pdf but not in my applicaton.
When ever i'll click or open that pdf it will ask me to open that pdf in another application of pdf viewer availbale on my device i wnt to know that is it possible & if possible how can i do that?
-Thanx in advance
You need to use only apple PDF viewer afaik. I dont know if I am wrong here. (Please correct me in this case)
To open PDF in iBook app, use this code
NSString *stringURL = #"itms-books:";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
NSString *stringURL = #"itms-bookss:";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

How to register an app to respond to a custom URL scheme opening request?

Like this:
NSString *stringURL = #"appname://";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
I slightly remember it was necessary to write a value-key to Info.plist. How?
Add this to plist .
The app will by called by #"readtext://" url
This seems to be the question that I answered (with screenshots & source code) here.
And I've posted a full walkthrough of how to do this on my blog.

Open Documents from iBooks in my application

Is it possible to open a document from iBooks in my application? I found only that:
NSString *stringURL = #"itms-books:";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
but with this I can only open iBooks from my application.
No that is not possible, there is no API to get document from iBooks.

iPhone: Open a url Programmatically

I am new to iPhone.
I want to open an url in my application.
How can I do this task? Please suggest me and provide some useful link.
Apparently the link given above is outdated. Here is the update link for the UIApplication class.
The quick and simple code snippet is:
// ObjC
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"http://www.google.com"]];
// Swift
UIApplication.shared.open(URL(string: "http://www.google.com")!, options: [:], completionHandler: nil)
Update (2016): The best way to do this nowadays is to instantiate and present an SFSafariViewController. This gives the user the security and speed of Safari, and access to any cookies or Safari features they may already have set without having to leave your app.
If you want to open the URL in Safari (and exit your application) you can use the openURL method of UIApplication
If you'd rather have it handled inside of your app, use WKWebView.
If you would like to open and just get the data from the URL, you could use NSString:
NSString *ans = [NSString stringWithContentsOfURL:url];
If what you are trying to get is an XML from a URL, you can directly use NSXMLParser:
NSURL *url = [[NSURL alloc] initWithString:urlstr];
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
// parse here
[parser release];
[url release];
On the other hand, if by opening you mean, open a URl in an embedded browser, you could use UIWebView class.
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"https://medium.com/the-traveled-ios-developers-guide/swift-3-feature-highlight-c38f94359731#.83akhtihk"]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"https://medium.com/the-traveled-ios-developers-guide/swift-3-feature-highlight-c38f94359731#.83akhtihk"]];
}
else{
[SVProgressHUD showErrorWithStatus:#"Please enable Safari from restrictions to open this link"];
}