didFinishPickingMediaWithInfo 函数进入无限循环

didFinishPickingMediaWithInfo function goes on infinite loop

看起来 didFinishPickingMediaWithInfo 函数正在进行无限循环,最终崩溃并在控制台中显示错误:

warning: could not execute support code to read Objective-C class data in >the process. This may reduce the quality of type information available.

就在我录制视频并按下选择按钮时,它崩溃了,因为它调用了 didFinishPickingMediaWithInfo。这是相关代码:

let imagePicker: UIImagePickerController! = UIImagePickerController()
let saveFileName = "/test.mp4"

             if (UIImagePickerController.isSourceTypeAvailable(.camera)) {
        if UIImagePickerController.availableCaptureModes(for: .rear) != nil {

            //if the camera is available, and if the rear camera is available, the let the image picker do this
            imagePicker.sourceType = .camera
            imagePicker.mediaTypes = [kUTTypeMovie as String]
            imagePicker.allowsEditing = false
            imagePicker.delegate = self as? UIImagePickerControllerDelegate & UINavigationControllerDelegate
            imagePicker.videoMaximumDuration = 60
            imagePicker.videoQuality = .typeIFrame1280x720
            present(imagePicker, animated: true, completion: nil)
        } else {
            postAlert("Rear camera doesn't exist", message: "Application cannot access the camera.")
        }
    } else {
        postAlert("Camera inaccessable", message: "Application cannot access the camera.")
    }
}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    print(123)
    imagePickerController(imagePicker, didFinishPickingMediaWithInfo: [saveFileName : kUTTypeMovie])

    let videoURL = info[UIImagePickerControllerReferenceURL] as? NSURL
    print("\(String(describing: videoURL))" )
    guard let path = videoURL?.path else { return }
    let videoName = path.lastPathComponent
    let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
    let documentDirectory = paths.first as String!
    let localPath = documentDirectory! + "/" + videoName
    guard  let imageData = NSData(contentsOfFile: localPath) else { return }
    let image = UIImage(data: imageData as Data)

    picker.dismiss(animated: true, completion: nil)
}
override func viewDidLoad() {
    super.viewDidLoad()
    self.imagePicker.delegate = self 
}

提前致谢!

您是从自身内部调用函数,此处:

  func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    print(123)
    imagePickerController(imagePicker, didFinishPickingMediaWithInfo: [saveFileName : kUTTypeMovie])

这导致了无限循环。