Reputation: 1957
I have a html link on my app called "download instructions pdf"
When I click this I want to download the pdf (stored within the app) to the iPad / iPhone locally and then open it with iBook.
A lot of similar questions mention WebView and use the ViewController, but I have already finished the majority of the app and when I used webview it opens a blank page and the app doesn't run.
This is my first iOS app and I havent used Objective C before so get confused when using the ViewController.
This is the code I have so far:
<a href="howtouse.pdf">download instructions pdf</a>
This opens the pdf, but as full screen which removes any navigation. So if the user wants to visit another part of the app they must re open the app which isnt user friendly!
I am using xcode 4.6.3 iPad/iPhone simulator 6.1
I been stuck on this for hours, any help would be great, thanks!
Upvotes: 0
Views: 1793
Reputation: 537
I created an example where UIDocumentInteractionController is used. I uploaded to Github and you can download it here:
https://github.com/cjimenezpacho/openpdfibooks
Basically is this piece of code in a IBAction and the required delegate methods (very similar to link sp4rkbr):
NSURL *url = [[NSBundle mainBundle]
URLForResource: @"iPhoneintro" withExtension:@"pdf"];
self.docController = [UIDocumentInteractionController interactionControllerWithURL:url];
self.docController.delegate = self;
[self.docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
Links to Apple documentation:
Upvotes: 1
Reputation: 500
For the download part, take a look at some NSURLConnection samples
After you downloaded the PDF into a NSData, write it to the Documents path which can me found this way:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:@"yourFilename"];
For opening it, try UIDocumentInteractionController this way
Upvotes: 2