title: How to remove file after QLPreviewController is dismissed?
body: <p>My app requieres to download and show files in a <code>QLPreviewController</code>. In some situations, this files must be temporary, that is, after user finish the QLPreviewController, files should be deleted from internal storage.</p>
  
  <p>I was trying to call a completion block removing these files as the following code shows:</p>
  
  <pre><code>func launchPreview(QLpreviewItem: QLPreviewItem, completion: @escaping () -&gt; Void) {
      previewItem = QLpreviewItem
      let previewController = QLPreviewController()
      previewController.dataSource = self
      self.present(previewController, animated: true, completion: {
          completion()
      })
  }
  </code></pre>
  
  <p>The completion block looks like that and it's working fine:</p>
  
  <pre><code>if fileManager.fileExists(atPath: path) {
      try! fileManager.removeItem(atPath: path)
  }
  </code></pre>
  
  <p>The problem with this approach is when users tries to share the file on the previewController... It was removed just after show it on the preview controller, so it is not available.</p>
  
  <p>Is there any way to execute code after previewController is dismissed?</p>
  
  <p>Alternatively, what about to store files on a temporary directory? It will be possible on iOS?</p>
  
  <p>I'm using the following code to download and save my files:</p>
  
  <pre><code>let destination: DownloadRequest.DownloadFileDestination = { _, _ in
      let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] //path
      let fileURL = documentsURL.appendingPathComponent(attachment.name) //url
      return (fileURL, [.createIntermediateDirectories])
  }
  
  Alamofire.download(RestHelper.apiV1 + "/attachments/\(attachment.id)", to: destination).response { response in
      //Some code here
  }
  </code></pre>
  
  <p>Maybe it is more simple to change the destination to a tmp directory, but I'm not sure.</p>
  
  <p>Thanks!</p>