The UIImagePickerController is getting an Exceptionio error, but I don't know why.

Asked 2 years ago, Updated 2 years ago, 114 views

When I tap the image and select the image from the album, it stops with an error.
I copied the current code to another project file and ran it, but it worked fine, so I don't know what caused it.

Below is the current source.

@IBAction functapProfileImage(_sender:Any){
    showAlert()
}



func sourceTypeImagePicker(sourceType:UIImagePickerController.SourceType){

    letcameraPicker=UIImagePickerController()
        cameraPicker.sourceType=sourceType
        cameraPicker.delegate=self
        cameraPicker.allowsEditing=true
        present(cameraPicker, animated:true, completion:nil)

}


funcimagePickerControllerDidCancel(_picker:UIImagePickerController){
    picker.dismiss(animated:true, completion:nil)
}


funcimagePickerController(_picker:UIImagePickerController, didFinishPickingMediaWithInfo:[UIImagePickerController.InfoKey:Any]){

    iflet pickerImage = info [.editedImage] as ?UIImage{
        self.profileImage.image=pickerImage
            picker.dismiss(animated:true, completion:nil)

    }
}


func showAlert(){

    let alertController=UIAlertController(title: "Select", message: "Which do you want to use?" preferredStyle:.actionSheet)

        let action1 = UIAlertAction(title: "Camera", style: .default) {(alert) in

            let sourceType —UIImagePickerController.SourceType=.camera
                self.sourceTypeImagePicker(sourceType:sourceType)

        }
    let action2 = UIAlertAction(title: "Album", style: .default) {(alert) in

        let sourceType —UIImagePickerController.SourceType=.photoLibrary
            self.sourceTypeImagePicker(sourceType:sourceType)

    }

    let action3 = UIAlertAction(title: "Cancel", style: .cancel)


        alertController.addAction(action1)
        alertController.addAction(action2)
        alertController.addAction(action3)
        self.present(alertController, animated:true, completion:nil)

}

Secure is modeled, instantiated, and running in Viewdidload.

The following models are available:

class checkPermission{

    init(){

    }

    func checkCamera(){
        PHPhotoLibrary.requestAuthorization {(status) in
            switch(status){


            case.notDetermined:
                print ("notDetermined")
            case.restricted:
                print("restricted")
            case.denied:
                print("denied")
            case.authorized:
                print("authorized")
            case.limited:
                print("limited")
            @unknown default:
                break
            }
        }
    }
}

When I copied the code in question to another project file, it worked fine and I was able to select an image from the album.
The difference between the problematic project and the problematic project is whether Firebase is installed or not.However, I think it doesn't really matter because I haven't sent any data to Firebase yet, but I'm not sure because it works well for projects that don't have Firebase installed.

The operating environment is M1's MacBook Pro.
Firebase communication without images turned off arm64 and worked fine.

Thank you for your advice.

Enter a description of the image here

swift firebase uiimagepickercontroller

2022-09-30 19:56

1 Answers

The location URLByAppendingPathExtension (i.e., appendingPathExtension(_:) function
https://developer.apple.com/documentation/foundation/url/1780122-appendingpathextension) has an exception error.

https://developer.apple.com/forums/thread/670640
I think the error statement in is very similar to the error statement in the image in the question, and the problem is occurring in a similar place.

I think it would be easier for the respondents to understand and respond to the error statement instead of the image, so let's try to do so from now on.

Exceptionio→Exception


2022-09-30 19:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.