如何使用ReplayKit实现共享?

时间:2019-12-23 02:00:17

标签: ios swift video screen-recording replaykit

我正在尝试使用ReplayKit记录我的应用程序,然后为用户提供共享或删除记录的选项。删除工作正常,但是我无法使共享部分正常工作。我试图将RPPreviewViewControllerMode与.shared一起使用,但是XCode无法识别它。我还尝试了UIActivityViewController,它会弹出共享菜单-但是,如果我尝试访问记录,它将不起作用。最后,我尝试了PreviewControllerDelegate,它允许用户编辑和保存视频,但不能共享它。

我已经在下面发布了我的代码。请指教,谢谢!

Group

}

1 个答案:

答案 0 :(得分:3)

也许是由于.automatic模态演示,因为在iOS 13中,当您弹出控制器时,它不能覆盖全屏。因此,尝试.fullScreen,它对我有帮助:

func stopRecording() {
    recorder.stopRecording { (preview, error) in

        guard preview != nil else {
            print("Preview controller not available")
            return
        }

        let alert = UIAlertController(title: "Recording finished", message: "Would you like to share or delete your recording?", preferredStyle: .alert
        )

        let deleteAction = UIAlertAction(title: "Delete", style: .destructive, handler: { (action) in
            self.recorder.discardRecording {
                print("Recording discarded successfully.")
            }
        })

        let shareAction = UIAlertAction(title: "Share", style: .default, handler: { (action) in
            // Try .fullScreen
            preview?.modalPresentationStyle = .fullScreen
            preview?.previewControllerDelegate = self
            self.present(preview!, animated: true, completion: nil)
        })


        alert.addAction(deleteAction)
        alert.addAction(shareAction)
        self.present(alert, animated: true, completion: nil)

        self.isRecording = false
        self.viewReset()
    }
}