Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save document to "Files" App in swift [duplicate]

Tags:

xcode

swift

I just created a PDF document in my app and I want to save the document on the device in a way that the "Files" app can access the saved document.

When you download a PDF document in Safari there is an option to save the document to the "Files" app, which is what I'm trying to do.

I Googled for several hours but wasn't able to find any useful methods.

like image 542
ARUN KUMAR Avatar asked May 02 '18 06:05

ARUN KUMAR


People also ask

How do I copy files in iOS app?

Tap Move to transfer items to another cloud storage device or your iPad. Tap the destination and then tap the folder (if available). Tap Copy to move the file. The files are copied to the destination.

How do I save a file in Xcode?

File -> Save saves the current file, which is the one in the currently active editing pane. You can hold down the Option key when choosing from the File menu to save all files that have changes. (The default key equivalents are Command-S and Command-Option-S.)

What is LSSupportsOpeningDocumentsInPlace?

LSSupportsOpeningDocumentsInPlace. A Boolean value indicating whether the app may open the original document from a file provider, rather than a copy of the document.


1 Answers

If you have access to your PDFdata then you could present the user with a UIActivityViewController where they can then save it to Files, or share it with any of the other available options:

let activityViewController = UIActivityViewController(activityItems: ["Name To Present to User", pdfData], applicationActivities: nil) present(activityViewController, animated: true, completion: nil) 

enter image description here

like image 158
rbaldwin Avatar answered Sep 30 '22 20:09

rbaldwin