1

I am trying to create a folder for my app in the Files app for access when i want to save a file from my app

In iOS 12 and earlier i could achieve this by enabling

Application supports iTunes file sharing and Supports opening documents in place as shown below

enter image description here

Since updating to iOS 13, the same folder that used to show up in iOS 12 no-longer shows.

What has changed and how can i get this resolved in iOS 13?

I use the extension below to save files:

extension WebViewController:  URLSessionDownloadDelegate {
    func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) {

        // create destination URL with the original pdf name
        guard let url = downloadTask.originalRequest?.url else { return }
        let documentsPath = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0]
        let destinationURL = documentsPath.appendingPathComponent(url.lastPathComponent)
        // delete original copy
        try? FileManager.default.removeItem(at: destinationURL)
        // copy from temp to Document
        do {
            try FileManager.default.copyItem(at: location, to: destinationURL)
             DispatchQueue.main.asyncAfter(deadline: .now() + 0.2){
            let activityViewController = UIActivityViewController(activityItems: [self.fileName, destinationURL], applicationActivities: nil)
                if(UIDevice.current.userInterfaceIdiom == .pad){
                    if let popOver = activityViewController.popoverPresentationController {
                        popOver.sourceView = self.view
                        popOver.sourceRect = self.view.bounds
                        popOver.barButtonItem = self.navigationItem.rightBarButtonItem
                        self.present(activityViewController, animated: true, completion: nil)
                    }
                }
                else{
                    self.present(activityViewController, animated: true, completion: nil)
                }
            }
        } catch let error {
            print("Copy Error: \(error.localizedDescription)")
        }
    }
}
tendai
  • 1,172
  • 1
  • 11
  • 22
  • I store docx, pdf, xlsx. But even before storing a file, normally the 'Save to files' option would reveal a folder inside the files app with my app name – tendai Sep 26 '19 at 23:58
  • I have edited my question to show how i'm saving files – tendai Sep 27 '19 at 00:04
  • 2
    `let documentsPath = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0]` That is not the Documents directory. The files app shows your Documents directory. – matt Sep 27 '19 at 00:51
  • is there an explanation for this working in iOS 12? – tendai Sep 27 '19 at 06:44

1 Answers1

0

For those looking for the answer to the specific problem above,

Updating to iOS 13.1 seems to fix this issue, so i'm not sure if this was a bug of some sort

tendai
  • 1,172
  • 1
  • 11
  • 22