'UIVideoEditorController delegate method called twice

I'm using UIVideoEditorController, but the success delegate method called twice for me. However, all pointers of all passed objects tell it sends exactly the same data.

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)

And then the following method prints "here" 2 times.

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


Solution 1:[1]

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

Solution 2:[2]

yes, I know, this bad way but workin :)

var isSaved:Bool = false

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

Solution 3:[3]

Can you please debug that you UIViewController that using UIVideoEditorController is reallocating properly when user leaves the screen. Like after leaving the screen or going back from the screen.

Might be one object of your UIViewController in memory that's why your method called twice.

To debug this

  • create deinit{ print("deallocating") } for you UIViewController.
  • add break point on print.
  • then make sure deinit is getting called.

Hope it will help you. :)

Solution 4:[4]

this work for me

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

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

Solution 5:[5]

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

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ?????? ?????
Solution 2 e.john
Solution 3 bestiosdeveloper
Solution 4 L.logan
Solution 5 Eric Aya