Use of undeclared identifier 'kUTTypeMovie'

后端 未结 6 1605
傲寒
傲寒 2020-12-13 16:32

I am getting the error message - Use of undeclared identifier \'kUTTypeMovie\'

in the below code -

-(IBAction)selectVideo:(id)sende         


        
6条回答
  •  时光说笑
    2020-12-13 17:16

    Swift 4 answer, with video camera code and imagePicker delegate:

    import MobileCoreServices
    

    Open Video Camera

       @IBAction func openVideoCamera(_ sender: Any) {
         if UIImagePickerController.isSourceTypeAvailable(.camera) {
            let imagePicker = UIImagePickerController()
            imagePicker.delegate = self
            imagePicker.sourceType = .camera
            imagePicker.mediaTypes = [kUTTypeMovie as String]
            imagePicker.videoMaximumDuration = 10 // or whatever you want
            imagePicker.videoQuality = .typeMedium
            imagePicker.allowsEditing = false
            present(imagePicker, animated: true, completion: nil)
        }
    

    ImagePicker delegate:

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        let mediaType = info[UIImagePickerControllerMediaType] as AnyObject
    
        if mediaType as! String == kUTTypeMovie as String {
                let videoURL = info[UIImagePickerControllerMediaURL] as? URL
                print("VIDEO URL: \(videoURL!)")
        }
        dismiss(animated: true, completion: nil)
    }
    

提交回复
热议问题