title: iOS 12: ReplayKit is broken
body: <p>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: </p>
  
  <p><a href="https://i.stack.imgur.com/OtskA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OtskA.png" alt=""></a></p>
  
  <p>a completely black screen.</p>
  
  <p>This hasn't happened to me before and it is extremely frustrating. This is how I use ReplayKit to record the screen:</p>
  
  <pre><code>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")
      }
  }
  </code></pre>
  
  <p>When it works, all the print statements are printed, but when the black screen appears the last print statement is "presented". </p>
  
  <p>I am absolutely desperate for some help because I have no idea how to get around this. ANY help would be much appreciated.</p>
  
  <p>THANKS</p>
  
  <hr>
  
  <p><strong>Edit:</strong> 
  I just realised that I am using an 'AVCaptureVideoPreviewLayer` if that may be the issue. If so, what's the fix?</p>