Elena Rubilova
Elena Rubilova

Reputation: 469

UIImagePickerController didFinishPickingMediaWithInfo not being called with cameraOverlyView

I have UIImagePickerController with cameraOverlyView. I added tap gesture recognizer to the overlay view - when user taps on the view the recording should be stopped and saved:

let mediaUI = UIImagePickerController()
    mediaUI.sourceType = sourceType
    mediaUI.mediaTypes = [kUTTypeMovie as String]
    mediaUI.allowsEditing = true
    mediaUI.delegate = self

    //customView stuff
    let customViewController = CustomOverlayViewController(
        nibName:"CustomOverlayViewController",
        bundle: nil
    )
    let customView:CustomOverlayView = customViewController.view as! CustomOverlayView
    customView.frame = delegate.view.frame //self.picker.view.frame
    let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(cameraViewTapped(tapGestureRecognizer:)))
    customView.cameraView.addGestureRecognizer(tapGestureRecognizer)
    customView.delegate = delegate


    delegate.present(mediaUI, animated: true, completion: {
        mediaUI.cameraOverlayView = customView
    })

gesture recognizer calls this:

@objc func cameraViewTapped(tapGestureRecognizer: UITapGestureRecognizer)
{
    if isRecording {
        self.picker!.stopVideoCapture()
        self.recordButton.isEnabled = false
        print("stopped")
        isRecording = false
    } else {
        self.picker!.startVideoCapture()
        print("started")
        isRecording = true
    }
}

delegate method:

extension HomeViewController: UIImagePickerControllerDelegate {
func imagePickerController(_ picker: UIImagePickerController,
                           didFinishPickingMediaWithInfo info: [String : Any]) {
    print("didFinishPickingMediaWithInfo")
    dismiss(animated: true, completion: nil)

    guard
        let mediaType = info[UIImagePickerControllerMediaType] as? String,
        mediaType == (kUTTypeMovie as String),
        let url = info[UIImagePickerControllerMediaURL] as? URL,
        UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(url.path)
        else {
            return
    }

    // Handle a movie capture
    UISaveVideoAtPathToSavedPhotosAlbum(
        url.path,
        self,
        #selector(video(_:didFinishSavingWithError:contextInfo:)),
        nil)
}

}

My question is how to get recording from the picker controller? Delegate method didFinishPickingMediaWithInfo is not called because of the overlay view: UIImagePickerController didFinishPickingMediaWithInfo not being called when cameraOverlyView property is assigned

Upvotes: 0

Views: 87

Answers (1)

Elena Rubilova
Elena Rubilova

Reputation: 469

Solved the issue by adding the following line of code:

mediaUI.showsCameraControls = false

Upvotes: 0

Related Questions