gpt4 book ai didi

swift - didFinishPickingMediaWithInfo 函数进入无限循环

转载 作者:行者123 更新时间:2023-11-28 15:24:58 29 4
gpt4 key购买 nike

它看起来像 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])

这会导致无限循环。

关于swift - didFinishPickingMediaWithInfo 函数进入无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45400011/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com