2

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?

J.Treutlein
  • 963
  • 8
  • 23
  • Yes that is what comes up when the RPPreviewController is meant to be displayed – J.Treutlein Sep 28 '18 at 09:15
  • I am in the exact same situation... and I too am using an AVCaptureVideoPreviewLayer! The only difference between your situation and mine is that I'm using Objective-C. This is very frustrating as something changed with a recent version of iOS that has broke this functionality. If you've found a work around please post it! – VTPete Dec 05 '18 at 12:35
  • @VTPete Yes I did manage to find a work around (not perfect but worked for me). I found this class on GitHub: https://github.com/giridharvc7/ScreenRecord I then tweaked it to fit my app and thankfully it now works almost everytime. Hope this works for u too, good luck! – J.Treutlein Dec 05 '18 at 20:31
  • I will give this a shot... I notice it's Switch. I think I can just create the necessary bridging headers to use it. Out of curiosity, do you have any idea why this code works and our's doesn't? I see the author took the approach of managing the sample buffer manually. Thanks! – VTPete Dec 06 '18 at 21:28

0 Answers0