Метод делегата UIVideoEditorController вызывается дважды
Я использую UIVideoEditorController, но метод делегата успеха вызывается для меня дважды. Однако все указатели всех переданных объектов сообщают, что он отправляет одни и те же данные.
let editor = UIVideoEditorController()
editor.videoMaximumDuration = 10.0
editor.videoQuality = .typeIFrame1280x720
editor.delegate = self
editor.videoPath = // some path goes here
self.present(editor, animated: true, completion: nil)
И тогда следующий метод печатает "здесь" 2 раза.
func videoEditorController(_ editor: UIVideoEditorController, didSaveEditedVideoToPath editedVideoPath: String) {
print("here")
self.dismiss(animated: true, completion: nil)
}
5 ответов
func videoEditorController(_ editor: UIVideoEditorController, didSaveEditedVideoToPath editedVideoPath: String) {
editor.delegate = nil
editor.dismiss(animated: true)
}
Да я знаю, это плохо, но работаю:)
var isSaved:Bool = false
func videoEditorController(_ editor: UIVideoEditorController, didSaveEditedVideoToPath editedVideoPath: String) {
if(!isSaved) {
print("here")
self.isSaved = true
}
self.dismiss(animated: true, completion: nil)
}
Не могли бы вы отладить, что ваш UIViewController, который с помощью UIVideoEditorController перераспределяется правильно, когда пользователь покидает экран. Как после ухода с экрана или возврата с экрана.
Может быть один объект вашего UIViewController в памяти, поэтому ваш метод вызывается дважды.
Отладить это
- Создайте
deinit{ print("deallocating") }
для вас UIViewController. - добавить точку останова на печать.
- тогда убедитесь, что звонят deinit.
Надеюсь, это поможет вам.:)
Эта работа для меня
- (void)videoEditorController:(UIVideoEditorController *)editor didSaveEditedVideoToPath:(NSString *)editedVideoPath {
[editor dismissViewControllerAnimated:YES completion:^{
NSLog(@"path = %@", editedVideoPath);
}];
}
func videoEditorController(_ editor: UIVideoEditorController,
didSaveEditedVideoToPath editedVideoPath: String) {
// This is the trimed video url
print(editedVideoPath)
dismiss(animated:true)
}