Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在swift中使用UIDocumentPickerViewController(documentTypes:)_Ios_Swift - Fatal编程技术网

Ios 在swift中使用UIDocumentPickerViewController(documentTypes:)

Ios 在swift中使用UIDocumentPickerViewController(documentTypes:),ios,swift,Ios,Swift,在我的代码中使用UIDocumentPickerViewConroller在应用程序中选择音频文件时,出现了此错误,我在UIDocumentPickerViewController中找不到(documentTypes:) iOS 14.0中不推荐使用UIDocumentPickerMode中的UIDocumentPickerServiceController(documentTypes:[String]) 该方法将替换为此UIDocumentPickerViewController(用于打开c

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


iOS 14.0中不推荐使用UIDocumentPickerMode中的UIDocumentPickerServiceController(documentTypes:[String])

该方法将替换为此UIDocumentPickerViewController(用于打开contentTypes 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)

iOS 14.0中不推荐使用UIDocumentPickerMode中的UIDocumentPickerServiceController(documentTypes:[String])

该方法将替换为此UIDocumentPickerViewController(用于打开contentTypes 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)

导入导入MobileCoreServices框架了吗?导入导入了导入MobileCoreServices框架了吗?我尝试了,但无法导入UniformTypeIdentifiers。我应该更新Xcode吗?哪是你的Xcode版本?我现在正在下载12.5,我已经下载了Xcode版本12.2,它正在运行。我会再试一次。我试过了,但我无法导入UniformTypeIdentifiers。我应该更新Xcode吗?哪一个是你的Xcode版本?我现在正在下载12.5我已经下载了Xcode版本12.2,它可以正常工作了,我会再试一次