Swift UIImagePickerController is not sensitive when clicking the Select button

Upload Image Button

@IBAction func uploadImageAction(_ sender: UIButton) {

        let picker = UIImagePickerController()

        picker.sourceType = .photoLibrary

        picker.delegate = self

        picker.allowsEditing = true

        picker.modalPresentationStyle = .fullScreen

        present(picker, animated: true)

    }

Delegate Functions

extension SignUpViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {

    

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]){

        

        

        picker.dismiss(animated: true, completion: nil)

        guard let image = info[UIImagePickerController.InfoKey.editedImage] as? UIImage else {

            return

        }

        

        guard let imageData = image.pngData() else {

            return

        }

        

        

        storage.child("images/file.png").putData(imageData, metadata: nil) { _, error in

            guard error == nil else {

                print("Failed to upload")

                return

            }

            self.storage.child("images/file.png").downloadURL { url, error in

                guard let url = url, error == nil else{

                    return

                }

                let urlString = url.absoluteString

                print("Download URL :- \(urlString)")

                

            }

        }

        

    }

    



    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {

        picker.dismiss(animated: true, completion: nil)

        

        func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {

            // Solve the problem that the cancel button is not sensitive when selecting photos after iOS 11

            if (UIDevice.current.systemVersion as NSString).floatValue < 11.0 {

                return

            }

            if (viewController.isKind(of: NSClassFromString("UIImagePickerController")!)){

                for (index,obj) in viewController.view.subviews.enumerated() {

                    if obj.frame.size.width < 42 {

                        viewController.view.sendSubviewToBack(obj)

                    }

                }

            }

        }

    }

    

}

Did you check that the func is called, by adding some print:

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]){

        print("func was called")
        picker.dismiss(animated: true, completion: nil)
     guard let image = info[UIImagePickerController.InfoKey.editedImage] as? UIImage else {
            print("image is nil")
            return
        }

        guard let imageData = image.pngData() else {
            print("imageData is nil")
            return
        }

Do the same in any place where you return prematurely.

Swift UIImagePickerController is not sensitive when clicking the Select button
 
 
Q