iOS 12: ReplayKit is broken

2019-05-25 05:44发布

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?

0条回答
登录 后发表回答