Skip to content
This repository has been archived by the owner on Aug 1, 2019. It is now read-only.

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

Open
lordjjl opened this issue Nov 24, 2017 · 7 comments

Comments

@lordjjl
Copy link

lordjjl commented Nov 24, 2017

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.

@lordjjl
Copy link
Author

lordjjl commented Nov 25, 2017

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

@dodikk
Copy link

dodikk commented Nov 28, 2017

@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.

@dodikk
Copy link

dodikk commented Dec 13, 2017

@lordjjl , have you managed to solve the issue?

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

Thanks.

@alexandremorgado
Copy link

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

@dodikk
Copy link

dodikk commented Jan 2, 2018

@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.

@alexandremorgado
Copy link

@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)
    }
    
}

@dodikk
Copy link

dodikk commented Jan 3, 2018

@alexandremorgado , thanks for sharing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants