Search code examples
iosswiftiphoneuikit

open recorder with button click


I've button and want to open a video recorder, but my code only opens photo capture any easy solutions ?

    @IBAction func uploadVideoButton(_ sender: UIButton) {
        let vc = UIImagePickerController()
        vc.sourceType = .camera
        vc.allowsEditing = true
        vc.delegate = self
        present(vc, animated: true)
    }

Solution

  • You need to tell the picker what kind of media you want.

    vc.sourceType = .camera
    vc.mediaTypes = [kUTTypeMovie as String]
    

    Remember to import MobileCoreServices too.

    Having just quickly tested this, kUTTypeMovie is deprecated so you should look into UTTypeMovie