RPScreenRecorder.shared.stopRecording块未调用

时间:2018-11-25 18:36:59

标签: ios swift replaykit

我正在使用ReplayKit来记录屏幕变化。我创建了一个示例应用程序来测试此框架。 stopRecording块永远不会被调用。这是Apple框架的问题吗?

class ViewController: UIViewController {
    @IBOutlet weak var imageView: UIImageView!
    let colors:[UIColor] = [UIColor.blue, UIColor.orange, UIColor.red, UIColor.blue]
    let recorder = RPScreenRecorder.shared()
    var isStarted = false
    override func viewDidLoad() {
        super.viewDidLoad()
        let count = self.colors.count
        // Do any additional setup after loading the view, typically from a nib.
        Timer.scheduledTimer(withTimeInterval: 1, repeats: true) {[weak self] (timer) in
            self?.view.backgroundColor = self?.colors[Int.random(in: 0..<count)]
        }

    }

    @IBAction func startOrStopRecorder(_ sender: Any) {
        let button = sender as! UIButton
        if self.isStarted{
            recorder.stopRecording { (preview, error) in
                print("stopped")
                if let thePreview = preview {
                    self.show(thePreview, sender: nil)
                }
            }
            button.setTitle("Start", for: .normal)
        } else {
            recorder.startRecording { (error) in
                print("started")
            }
            button.setTitle("Stop", for: .normal)
        }
        self.isStarted = !self.isStarted
    }

}

0 个答案:

没有答案