Friday, June 9, 2023
HomeiOS developmentswift - Learn how to import AVIF picture in iOS by PHPicker

swift – Learn how to import AVIF picture in iOS by PHPicker

I take advantage of PHPicker for person to import pictures, however UIImage not assist the pic of .AVIF, so I wish to get the origin knowledge of .AVIF pic, that is my code:

    func picker(_ picker: PHPickerViewController, didFinishPicking outcomes: [PHPickerResult]) {
        picker.dismiss(animated: true)
        for picture in outcomes {
            loadImagePickerResult(picture: picture)
    func loadImagePickerResult(picture: PHPickerResult) {
        if picture.itemProvider.canLoadObject(ofClass: UIImage.self) {
            picture.itemProvider.loadObject(ofClass: UIImage.self) { [weak self] newImage, error in
                guard let self = self else { return }
                if let _ = error {

                } else if let needAddImage = newImage as? UIImage {
                    let imageItem = ContentImageItem()
                    imageItem.picture = needAddImage
                    DispatchQueue.fundamental.async {
        } else if picture.itemProvider.hasItemConformingToTypeIdentifier(kUTTypeImage as String) {
            picture.itemProvider.loadItem(forTypeIdentifier: kUTTypeImage as String, choices: nil) { [weak self] merchandise, error in
                guard let self = self else { return }
                guard let url = merchandise as? URL else { return }
                var imageData: Knowledge?
                do {
                    imageData = strive Knowledge(contentsOf: url, choices: [.mappedIfSafe, .alwaysMapped])
                } catch {
                guard let selectedImageData = imageData else { return }
                /// selectedImageData is empty knowledge
        } else {


Once I select .AVIF pic, itemProvider can load the picture by “kUTTypeImage” typeIdentifier, and success to get the native path of the pic, however once I use Knowledge(contentsOf: ) to learn the origin knowledge, I can solely get an empty knowledge. So, is there any downside with this code?Does anybody have expertise in dealing with this matter?
url path and empty knowledge

I take advantage of “NSData(contentsOf:” to get the origin knowledge, however nonetheless is empty.



Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments