title: UIDocumentInteractionController: cannot use/save files
body: <p>In my app, I display some remote images or PDF files and want to give the user the ability to download them. In order to do so, I try to save them locally first in <code>.documentDirectory</code> before opening a <code>UIDocumentInteractionController</code> to handle the file.</p>
  <p>However, I am having an issue, which is that even if the action sheet opens fine and proposes all the expected options, in the end I can never use the file because of an error. Specifically:</p>
  <ul>
  <li>If I try to use the file in a mail, the mail opens but empty,</li>
  <li>If I try to use it in Whatsapp, I get an error saying &quot;The item cannot be shared. Please selected a different item.&quot;</li>
  <li>And if I choose &quot;Save to Files&quot;, the files action sheet briefly opens but closes immediately afterwards with an error in the console saying: <code>[ShareSheet] cancelled request - error: The operation couldn’t be completed. Invalid argument</code></li>
  </ul>
  <p>Here is the code I use to cache the remote file, then to open it with <code>UIDocumentInteractionController</code>:</p>
  <pre><code>URLSession.shared.downloadTask(with: url) { localUrl, response, error in
      if let localUrl = localUrl {
          do {
              let imageData = try Data(contentsOf: localUrl)
              let d = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last
              if let docUrl = d?.appendingPathComponent(url.lastPathComponent) {
                  try imageData.write(to: docUrl)
                  self.download(docUrl)
              }
          } catch {
              print(&quot;Oops: \(error)&quot;)
          }
      }
  }.resume()
  
  func download(_ url: URL) {
      DispatchQueue.main.async {
          let documentInteractionController = UIDocumentInteractionController()
          documentInteractionController.delegate = self
          documentInteractionController.url = url
          documentInteractionController.uti = url.typeIdentifier ?? &quot;public.data, public.content&quot;
          documentInteractionController.name = url.localizedName ?? url.lastPathComponent
          documentInteractionController.presentOptionsMenu(from: self.view.frame, in: self.view, animated: true)
      }
  }
  </code></pre>
  <p>Thank you for your help</p>