iOS 12: ReplayKit is broken

落爺英雄遲暮 提交于 2019-12-12 10:12:28

问题


I have been using ReplayKit for all past updates, but now with iOS 12 my recordings sometimes work, sometimes don't... but usually they don't. Most of the time when I stop the recording this is what I get:

a completely black screen.

This hasn't happened to me before and it is extremely frustrating. This is how I use ReplayKit to record the screen:

import ReplayKit

class ViewController: UIViewController, AVCaptureVideoDataOutputSampleBufferDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, RPPreviewViewControllerDelegate {

func startRecording() {

    func start() {
        guard RPScreenRecorder.shared().isAvailable else {
            print("Recording is not available at this time.")
            return
        }
        RPScreenRecorder.shared().isMicrophoneEnabled = micToggle
        RPScreenRecorder.shared().startRecording { [unowned self] (error) in
            guard error == nil else {
                print("There was an error starting the recording.")
                return
            }
            print("Started Recording Successfully")
            isRecording = true
        }
    }
    DispatchQueue.main.async {
        start()
    }
}

func stopRecording() {

    func stop() {
        RPScreenRecorder.shared().stopRecording { [unowned self] (preview, error) in
            print("Stopped recording")
            guard preview != nil else {
                print("Preview controller is not available.")
                return
            }
            onGoingScene = true
            preview?.previewControllerDelegate = self
            self.present(preview!, animated: true, completion: nil)
            print("presented")
            isRecording = false
        }
    }
    DispatchQueue.main.async {
        stop()
    }
}

func previewControllerDidFinish(_ previewController: RPPreviewViewController) {
    previewController.dismiss(animated: true, completion: nil)
    RPScreenRecorder.shared().discardRecording {
        print("discarded")
    }
}

When it works, all the print statements are printed, but when the black screen appears the last print statement is "presented".

I am absolutely desperate for some help because I have no idea how to get around this. ANY help would be much appreciated.

THANKS


Edit: I just realised that I am using an 'AVCaptureVideoPreviewLayer` if that may be the issue. If so, what's the fix?

来源:https://stackoverflow.com/questions/52551482/ios-12-replaykit-is-broken

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!