'iOS: Open saved image inside the native Files app

My app allows saving images to the native Files app. I do it like this:

func save(imageData: Data,
          toFolder folderName: String,
          withFileName fileName: String) {
    DispatchQueue.global().async {
        let manager = FileManager.default
        let documentFolder = manager.urls(for: .documentDirectory, in: .userDomainMask).last
        let folder = documentFolder?.appendingPathComponent(folderName)
        let file = folder?.appendingPathComponent(fileName)

        do {
            try manager.createDirectory(at: folder!, withIntermediateDirectories: true, attributes: [:])
            if let file = file {
                try imageData.write(to: file)
            }
        } catch {
            print(error.localizedDescription)
        }
    }
}

But when I tap on the image inside the Files app, I am navigated to my app, instead of the image just being open in the Files app.

How can this be changed?

Example of the same unwanted behavior that is happening on the Snapseed app (app by Google) https://media.giphy.com/media/Odnyy9J52HJjhmr0Fl/giphy.gif



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source