0
votes

I have an Xcode (iPhone) app with a WebView. My homepage in this WebView contains a PDF file. I can open this PDF file. But I cannot save it.

In normal Safari browser there are the buttons "Open in…" and "Open in "iBooks"". But in my WebView I can just open the PDF file. I'm not able to save/open to/in iBooks or any other app. Why that? Can somebody help me please? Thanks for every answer.

1
From where are you opening pdf file in webview? – Fawad Masud
I'm opening it directly from the internet, not from local directory. Can you help me please? – user4432864
Because your using a custom UIWebView you have to create the actions it includes. For downloading it's easy. Create a directory and then save your file to it. The to open in whatever applications are installed on the device you use UIDocumentInteractionController There are numerous tutorials on the web. Do some research first – soulshined

1 Answers

0
votes

You can download pdf file in form of NSData and save it in document directory.

NSURL *url = [NSURL URLWithString:@"deu-net.com/Berlin-Buch/14Buch.pdf"];
NSData *dataPdf = [NSData dataWithContentsOfURL:url];

//Get path directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

//Create PDF_Documents directory
documentsDirectory = [documentsDirectory stringByAppendingPathComponent:@"PDF_Documents"];
[[NSFileManager defaultManager] createDirectoryAtPath:documentsDirectory withIntermediateDirectories:YES attributes:nil error:nil];

NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory, @"**PUT FILENAME YOU WANT**"];

[dataPdf writeToFile:filePath atomically:YES];