I am able to successfully view a PDF from a website. I want to be able to download that PDF to the device, then access that file locally.
When the app is opened, it will check the online PDF's date. If it is newer than the locally-stored PDF, the app will download the new one, otherwise it opens the locally-stored PDF.
The code I am currently using:
PDFAddress = [NSURL URLWithString:@"http://www.msy.com.au/Parts/PARTS.pdf"];
request = [NSURLRequest requestWithURL:PDFAddress];
[webView loadRequest:request];
webView.scalesPageToFit = YES;
How am I able to achieve this?
With Swift version 3.0 syntax:
You need to read the File and Data Management Guide from Apple. It will describe which locations are available in the application sandbox for saving files locally and how to get a reference to those locations. It also has a section for reading and writing :)
Enjoy!
In Swift 4.1
If you want to save the Pdf's in a particular folder/directory inside Main Document Directory
Happy Coding :)
I have found one method which I tried myself:
This will store your PDF locally and load it into your UIWebView.
Hope this solves your problem.
I found a swift version for it:
Just remember to save the path file and you'll be able to fetch it whenever you need it.
I'd also recommend taking a look at ASIHTTPRequest for easy file downloading.