4

Im using replay kit to record my screen and when the preview screen pops up theres a cancel button to dismiss the screen but it doesn't do anything. I have the delegate func previewControllerDidFinish with the code to dismiss it but it doesn't go away. Does anyone know how to dismiss the window when pressing cancel? Thanks!

func previewControllerDidFinish(previewController: RPPreviewViewController) {
    print("Preview finish")

        // close preview window
        previewController.dismissViewControllerAnimated(true, completion: nil)
    }
coding22
  • 689
  • 1
  • 7
  • 28

2 Answers2

1

In swift 3.2

First:

class ViewController: UIViewController, RPPreviewViewControllerDelegate {

func previewControllerDidFinish(_ previewController: RPPreviewViewController) {
        previewController.dismiss(animated: true, completion: nil)
    }
}

Then when the stop recording button called, and set delegate in closure

if RPScreenRecorder.shared().isRecording {
RPScreenRecorder.shared().stopRecording { (previewController: RPPreviewViewController?, error: Error?) in
    if previewController != nil {
        let alertController = UIAlertController(title: "Recoring", message: "Do you wish to discard or view your recording?", preferredStyle: .alert)
        let discardAction = UIAlertAction(title: "Discard", style: .destructive, handler: nil)

        let viewAction = UIAlertAction(title: "View", style: .default, handler: { (action: UIAlertAction) in

            // set delegate here
            previewController?.previewControllerDelegate = self

            self.present(previewController!, animated: true, completion: nil)
        })

        alertController.addAction(discardAction)
        alertController.addAction(viewAction)
        self.present(alertController, animated: true, completion: nil)
    }
}

}

Jayce
  • 427
  • 5
  • 6
1

Try to implement this delegate

- (void)previewController:(RPPreviewViewController *)previewController didFinishWithActivityTypes:(nonnull NSSet<NSString *> *)activityTypes {

    [previewController dismissViewControllerAnimated:YES completion:^{

    }];
}
Ofir Malachi
  • 1,145
  • 14
  • 20