eBay/NMessenger

Crash when opening the camera/photo selector [PUPhotoPickerHostViewController _setCameraDevice:]: unrecognized selector sent

Opened this issue · 7 comments

This is potentially an iPhone X issue as I haven't had an opportunity to test on another device. Disabling the camera permissions allows the iOS photo picker to display correctly, so I think the crash is occurring in the custom camera view.

I've confirmed that is is also occurs on an iPhone 8 and with the demo NMessenger project. Is there a config that I'm missing? I have all of the permissions set in info.plist

@lordjjl , I guess, I've fixed that in #145 but my PR has not been merged yet since the maintainers are not too active. Please let me know if it was helpful.

@lordjjl , have you managed to solve the issue?

  1. Could you please attach your stacktrace?
  2. Have you succeeded with applying #145 ?
  3. If you've made another solution, a gist for the fix is welcome. A pull request is even more welcome.

Thanks.

@dodikk unfortunately your PR don't solve this bug. I had to implement my own CameraViewController class (a very simple use of UIImagePickerController).

@alexandremorgado , glad to hear you've solved the issue.

Could you please share your class as a comment or as a pull request?
Just in case someone else runs into the same issue.
Thanks.

@dodikk I was using the detault CameraViewController instance from NMessengerBarView:
open lazy var cameraVC: CameraViewController = CameraViewController()

So I just replaced by a simple class that I named PhotosViewController, it was not necessary change anything into NMessenger lib. Something like this:

class PhotosViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
    
    weak var cameraDelegate: CameraViewDelegate?
    
    func pickFromCameraRoll() {
        let pickerVC = UIImagePickerController()
        pickerVC.delegate = self
        pickerVC.allowsEditing = true
        pickerVC.sourceType = .photoLibrary
        pickerVC.modalPresentationStyle = .fullScreen
        
        if let presenterVC = cameraDelegate as? UIViewController {
            presenterVC.present(pickerVC, animated: true)
        }
    }
    
    func takePhotoFromCamera() {
        let pickerVC = UIImagePickerController()
        pickerVC.delegate = self
        pickerVC.allowsEditing = false
        
        guard UIImagePickerController.isSourceTypeAvailable(.camera) else {
            pickFromCameraRoll()
            return
        }
        
        pickerVC.sourceType = UIImagePickerControllerSourceType.camera
        
        if let presenterVC = cameraDelegate as? UIViewController {
            presenterVC.present(pickerVC, animated: true)
        }
        
    }
    
    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
        picker.dismiss(animated: true)
    }
    
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        var newImage: UIImage
        
        if let possibleImage = info[UIImagePickerControllerEditedImage] as? UIImage {
            newImage = possibleImage
        } else if let possibleImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
            newImage = possibleImage
        } else {
            return
        }
        
        cameraDelegate?.pickedImage(newImage)

        picker.dismiss(animated: true)
    }
    
}

@alexandremorgado , thanks for sharing.