2

I am using following code to record screen. It is working fine for ios10 and ios9

 @IBAction func btnRecordTapped(_ sender: UIButton) {

    if RPScreenRecorder.shared().isAvailable {


        if #available(iOS 10.0, *) {
            RPScreenRecorder.shared().startRecording(handler: { (error) in
                guard error == nil else {
                    print("Record failed with error \(error!.localizedDescription)")
                    return
                }

                DispatchQueue.main.async {
                    sender.removeTarget(self, action: #selector(self.btnRecordTapped(_:)), for: .touchUpInside)
                    sender.addTarget(self, action: #selector(self.stoprecording(button:)), for: .touchUpInside)

                    sender.setTitle("Stop", for: .normal)
                    sender.setTitleColor(.red, for: .normal)


                }


            })
        } else {

            RPScreenRecorder.shared().startRecording(withMicrophoneEnabled: false, handler: { (error) in

                guard error == nil else {
                    print("Record failed with error \(error!.localizedDescription)")
                    return
                }

                DispatchQueue.main.async {
                    sender.removeTarget(self, action: #selector(self.btnRecordTapped(_:)), for: .touchUpInside)
                    sender.addTarget(self, action: #selector(self.stoprecording(button:)), for: .touchUpInside)

                    sender.setTitle("Stop", for: .normal)
                    sender.setTitleColor(.red, for: .normal)


                }

            })
        }
    } else {
        print("Screen Reocrder not availble")
    }

}

I can see Prompt for permission in ios10 and ios9 but not for ios11

ios11 Completion ( closure) block never calls
I have already verified that method calls correctly if condition if RPScreenRecorder.shared().isAvailable { Also allows to let in

Please help me if anyone know about it

enter image description here

enter image description here

Prashant Tukadiya
  • 15,838
  • 4
  • 62
  • 98
  • Did you try on a physical device? Maybe related to [https://stackoverflow.com/questions/40024316](https://stackoverflow.com/questions/40024316/reading-from-public-effective-user-settings-in-ios-10) – mato Oct 03 '17 at 09:56
  • @mato Thanks for response Screen recording not supported in Simulator , Provided link has nothing related to issue – Prashant Tukadiya Oct 03 '17 at 09:58
  • There's a related thread here: https://forums.developer.apple.com/thread/87007 In my case, I restarted the iPad and I got asked again about giving permissions for screen recording the next time I started the app, and then it started working again. – endavid Jul 28 '18 at 18:20

1 Answers1

2

I had the same problem as you, so I thinked in updating to iOS 11.0.2 and it worked for me! Hope it help you too.

Just in case, here are my methods:

let recorder = RPScreenRecorder.shared()

@IBAction func recordingAction(_ sender: Any) {
        if recorder.isRecording {
            stopRecordAction()
        } else {
            startRecordAction()
        }
}

func startRecordAction() {
     recorder.startRecording{ (error) in
            if let error = error {
               print("❗️",error)
             }
      }
}

func stopRecordAction() {
            recorder.stopRecording{ (previewVC, error) in
                if let previewVC = previewVC {
                    previewVC.previewControllerDelegate = self
                    self.present(previewVC, animated: true, completion: nil)
                    if let error = error {
                        print("❗️",error)
                    }
                }
            }
    }

Methods of RPPreviewViewControllerDelegate:

func previewControllerDidFinish(_ previewController: RPPreviewViewController) {
        dismiss(animated: true, completion: nil)
    }

    func previewController(_ previewController: RPPreviewViewController, didFinishWithActivityTypes activityTypes: Set<String>) {
        /// This path was obtained by printing the actiong captured in "activityTypes"
        if activityTypes.contains("com.apple.UIKit.activity.SaveToCameraRoll") {
            recordFinshedMessage()
        }
    }
Maisa M.
  • 61
  • 2
  • I have the same problem with ReplayKit. It works fine on ipad pro 11 (iOS 13.3) but not iPhone 11 (iOS 13.6). Do you know of anything reason? – swiftlearneer Aug 25 '20 at 23:35