我有一个 PHPIckerViewController,它从 iOS 14 开始可用。我想从画廊获取图像,它是 WEBP 格式。但是 PHPicker 中的项目提供者无法加载这种格式的图像。请告诉我如何使用新的选择器在 UIButton 上选择和设置图像。
代码:
extension SixStepRegistrationViewController: PHPickerViewControllerDelegate {
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
let supportedRepresentations = [UTType.rawImage.identifier,
UTType.tiff.identifier,
UTType.bmp.identifier,
UTType.png.identifier,
UTType.jpeg.identifier,
UTType.webP.identifier,
]
for representation in supportedRepresentations {
if results[0].itemProvider.hasRepresentationConforming(toTypeIdentifier: representation, fileOptions: .init()) {
print(representation, " repr")
results[0].itemProvider.loadInPlaceFileRepresentation(forTypeIdentifier: representation) { (originalUrl, inPlace, error) in
DispatchQueue.main.async {
print(originalUrl, " ", inPlace)
self.addPhotoButton.setImage(UIImage(contentsOfFile: originalUrl!.path), for: .normal)
//self.dismiss(animated: true, completion: nil)
}
}
}
}
}
谢谢