在我的代码中使用UIDocumentPickerViewConroller选择应用程序中的音频文件时,出现此错误,并且我找不到(documentTypes: )at UIDocumentPickerViewController。

@IBAction func AddMusic(_ sender: UIButton) {
let documentPicker = UIDocumentPickerViewController(documentTypes: [kUTTypeAudio as String], in: .import)
documentPicker.delegate = self
documentPicker.allowsMultipleSelection = false
present(documentPicker, animated: true, completion: nil)
}
}
extension ViewController: UIDocumentPickerDelegate{
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]){
}
}发布于 2021-02-02 13:42:24
UIDocumentPickerViewController(documentTypes: String,in: UIDocumentPickerMode)在iOS 14.0中已弃用
该方法被替换为UIDocumentPickerViewController(forOpeningContentTypes contentTypes: UTType,asCopy: Bool)方法
首先,您需要导入UniformTypeIdentifiers
import UniformTypeIdentifiers因此,您可以按如下方式使用它
let supportedTypes: [UTType] = [UTType.audio]
let pickerViewController = UIDocumentPickerViewController(forOpeningContentTypes: supportedTypes, asCopy: true)
pickerViewController.delegate = self
pickerViewController.allowsMultipleSelection = false
pickerViewController.shouldShowFileExtensions = true
self.present(pickerViewController, animated: true, completion: nil)https://stackoverflow.com/questions/66003954
复制相似问题