How can i open default Files app with myapp folder programmatically?

Viewed 2312

I have folder with files in my app. How can i open default Files app with myapp folder programmatically?

This is similar folder of GarageBand App in Files.

enter image description here

1 Answers

You can open Files app in specific folder using shareddocuments: URL scheme and providing file path.


Example:

func getDocumentsDirectory() -> URL { // returns your application folder
    let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
    let documentsDirectory = paths[0]
    return documentsDirectory
}

let path = getDocumentsDirectory().absoluteString.replacingOccurrences(of: "file://", with: "shareddocuments://")
let url = URL(string: path)!

UIApplication.shared.open(url)


P.S:

For more information, read this article.

Related