I need to save a PDF document from URL into the device. Is it possible to save the PDF and access it from device file manager without using UIActivityViewController or UIDocumentInteractionController.
Asked
Active
Viewed 1,490 times
2
-
some answers were like this: https://stackoverflow.com/questions/51759148/download-pdf-and-save-to-the-files-in-iphone-not-to-the-app-data-swift – Thomas Paul Dec 06 '18 at 13:03
-
Think in distant past, I might have done the exact same thing!! If my memory serves me right, I created the PDF Using CoreGraphics. Once completed write/fetch the file using NSFileManager. Needless to say you will have to manually keep track of the File URL. To Create PDF check https://developer.apple.com/library/archive/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/GeneratingPDF/GeneratingPDF.html – iOSer Dec 06 '18 at 13:06
-
My requirement is different. Already have a pdf and we can access it through its url.Then I need to download it and add some comments on the pdf pages. Then I need to resend it to the server. – Thomas Paul Dec 06 '18 at 13:19
-
Can you elaborate? Are you getting the PDF from remote or something? – iOSer Dec 06 '18 at 13:22
-
yes... I will get the pdf's url from the server.. we can download and save it to the document directory or file. But the downloaded pdf will not shown when ever I try to open it through adobe reader app. – Thomas Paul Dec 06 '18 at 13:23
-
Well in that case! The toughest part is done away with :) Download the content of the PDF using NSURLSessions. I believe once downloaded, you will be provided with the temporary device URL. Just ensure that you move the contents of the temporary file to a more permanent location in your document directory. You can access it later and edit as per your needs. Thats it!! Just remember you will be playing with NSData here all through.. – iOSer Dec 06 '18 at 13:29
-
I have done the saving task... Can we access the saved pdf from adobe reader app or phone's file manager? – Thomas Paul Dec 06 '18 at 13:31
-
No you cant. You cannot use any other app to access data from your app. Meaning App x cannot access data in App y and viceversa – iOSer Dec 06 '18 at 13:32
-
This is my issue.. we can use the file after saving it into file . Ie using UIActivitycontroller and Documentinteraction controller.. right? .. is there any other way? – Thomas Paul Dec 06 '18 at 14:02
-
You can access your PDF file from adobe reader using UIActivitycontroller or Documentinteraction – canister_exister Dec 06 '18 at 14:51
2 Answers
6
Add these 2 keys in your Info.plist: LSSupportsOpeningDocumentsInPlace and UIFileSharingEnabled. And set YES as the value for both.
Now you will be able use the Files app to see any file saved by your app in Documents Directory.

Vlad M.
- 139
- 4
-
can I open the saved pdf using adobe reader's URL schema after setting LSSupportsOpeningDocumentsInPlace and UIFileSharingEnabled. Any idea?? – Thomas Paul Dec 07 '18 at 04:50
2
Swift 5.0 and iOS13
let documentController = UIDocumentPickerViewController(url: exportToURL, in: .exportToService)
self.present(documentController, animated: true, completion: nil)
exportToURL represent application local URL whichever file want to save into iPhone Files app.

Pratik Sodha
- 3,679
- 2
- 19
- 38