Search code examples
swifticlouduiactivityviewcontroller

Save PDF file to a user-defined default directory in iCloud Drive


I'm asking this question because I did not find any answer, and I'm starting to believe that it's not possible, due to security reasons. But who knows?

In my app, I simply let the user save a PDF file using UIActivityViewController. The user then chooses Save to file, then selects iCloud Drive.

Now, users ask me to be able to select a default location once and for all. Is it possible? This location would of course be outside the app container, then I suppose iOS won't grant access unless the user selected it itself.


Solution

  • Yes you can. Using UIDocumentPickerViewController you can ask for a directory, and you can save it in your app. This is explained in detail in Providing Access to Directories. iOS 13 and later.

    See also What's New in File Management and Quick Look for sample code saving a directory URL and then reusing it to set the base directory for a subsequent call to UIDocumentPickerViewController