UIVideoEditorController代理方法被调用两次

8
我正在使用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)

然后以下方法会打印出“here”2次。
func videoEditorController(_ editor: UIVideoEditorController, didSaveEditedVideoToPath editedVideoPath: String) {
    print("here")
    self.dismiss(animated: true, completion: nil)
}

当我链接到iOS 13时,即使用Xcode 11构建时,我遇到了这个错误。如果我使用Xcode 10或更早版本构建,则回调仅被调用一次。 - Theo
5个回答

6
func videoEditorController(_ editor: UIVideoEditorController, didSaveEditedVideoToPath editedVideoPath: String) {
    editor.delegate = nil
    editor.dismiss(animated: true)
}

2
感谢您提供这段代码片段,它可能会在短期内提供一些有限的帮助。通过展示为什么这是一个好的解决方案,适当的解释将极大地提高其长期价值,并使其对未来具有类似问题的读者更有用。请编辑您的答案以添加一些解释,包括您所做的假设。 - Toby Speight
它正在工作,谢谢 - Duc Trung Mai

1

是的,我知道这种方法不好,但它能工作 :)

var isSaved:Bool = false

func videoEditorController(_ editor: UIVideoEditorController, didSaveEditedVideoToPath editedVideoPath: String) {
   if(!isSaved) {
      print("here")
      self.isSaved = true
   }
       self.dismiss(animated: true, completion: nil)
   }

0
func videoEditorController(_ editor: UIVideoEditorController,
 didSaveEditedVideoToPath editedVideoPath: String) {

    // This is the trimed video url
    print(editedVideoPath)
    
   dismiss(animated:true)
}

0

请问您能否调试一下使用UIVideoEditorController的UIViewController,以确保用户离开屏幕后或从屏幕返回后正确重新分配内存。

可能是您的UIViewController中有一个对象在内存中,这就是为什么您的方法被调用两次的原因。

调试方法如下:

  • 为您的UIViewController创建deinit{ print("deallocating") }
  • 在print上添加断点。
  • 然后确保deinit被调用。

希望这能帮到您。 :)


0

这对我有用

- (void)videoEditorController:(UIVideoEditorController *)editor didSaveEditedVideoToPath:(NSString *)editedVideoPath {

    [editor dismissViewControllerAnimated:YES completion:^{
        NSLog(@"path = %@", editedVideoPath);
    }];    
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接