'Unable to select files form UIDocumentPickerViewController Swift

I am working on UIDocumentPickerViewController() in swift. After opening the document picker the files and images look blur and I can't able to select anyone of them. I have attached the screenshot and the code below. Any idea why these files and images are not selectable.

Files and images look are not selectable

extension BecomeMuftiTwoVC: UIDocumentPickerDelegate {
    func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
        guard let selectedFilesURL = urls.first else {
            return
        }
        let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
        let sandboxFileURL = dir.appendingPathComponent(selectedFilesURL.lastPathComponent)
        
        if FileManager.default.fileExists(atPath: sandboxFileURL.path) {
            print("Already File Exist")
        }
        else {
            
            do{
                try FileManager.default.copyItem(at: selectedFilesURL, to: sandboxFileURL)
                print("Copied Files")
            }
            catch{
                print("Files Are not exist ")
                
            }
        }
    }
}
//MARK: - Import File Btn Action
@IBAction func importFile(_ sender: Any) {
    let documentPicker = UIDocumentPickerViewController(documentTypes: [KUTTypedPlainText], in: .import)
    documentPicker.delegate = self
    documentPicker.allowsMultipleSelection = false
    present(documentPicker, animated: true, completion: nil)


Solution 1:[1]

Your line

let documentPicker = UIDocumentPickerViewController(documentTypes: [KUTTypedPlainText], in: .import)

seems to initialize a document picker for plain-text files only.

Try this instead:

let documentPicker = UIDocumentPickerViewController(documentTypes: [kUTTypeImage as String], in: .import)

Also, be careful as the initializer init(documentTypes:in:) is deprecated since iOS14.0. So for iOS14 and above, you should use:

let documentPicker = UIDocumentPickerViewController(forOpeningContentTypes: [.heic, .heif, .livePhoto, .image])

Solution 2:[2]

are you using simulator? or real device?

in simulator you can't select files from document picker... but if you want to test your code and you need to select files watch this answer

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 Torreip
Solution 2 Amin Rezaew