Posts

Post not yet marked as solved
0 Replies
927 Views
Why won't RPScreenRecorder record the mic, even though it is enabled, if the permissions popup doesn't appear? It works when the popup appears but attempts after restarting the app don't record the mic. here's the very simple app i made just to test this feature for a larger app.I have tested this exact application on iOS 11 and it works every time.However on iOS 12+ it only works when the permission popup appears and that's every 8 minutes. It should work every time after giving permissions.import UIKit import ReplayKit class ViewController: UIViewController, RPPreviewViewControllerDelegate { private let recorder = RPScreenRecorder.shared() private var isRecording = false override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } @IBAction func react() { if !isRecording { let alert = UIAlertController(title: "Record", message: "Would you like to record a video?", preferredStyle: .alert) let okay = UIAlertAction(title: "Okay", style: .destructive, handler: { (action: UIAlertAction) in self.startRecording() }) alert.addAction(okay) self.present(alert, animated: true, completion: nil) } else { stopRecording() } } private func startRecording() { guard self.recorder.isAvailable else { print("Recording is not available at this time.") return } self.recorder.isMicrophoneEnabled = true self.recorder.startRecording{ [unowned self] (error) in guard error == nil else { print("There was an error starting the recording.") return } print("Started Recording Successfully") self.isRecording = true } } private func stopRecording() { recorder.stopRecording { [unowned self] (preview, error) in print("Stopped recording") guard preview != nil else { print("Preview controller is not available.") return } let alert = UIAlertController(title: "Recording Finished", message: "Would you like to edit or delete your recording?", preferredStyle: .alert) let deleteAction = UIAlertAction(title: "Delete", style: .destructive, handler: { (action: UIAlertAction) in self.recorder.discardRecording(handler: { () -> Void in print("Recording suffessfully deleted.") }) }) let editAction = UIAlertAction(title: "Edit", style: .default, handler: { (action: UIAlertAction) -> Void in preview?.previewControllerDelegate = self self.present(preview!, animated: true, completion: nil) }) alert.addAction(editAction) alert.addAction(deleteAction) self.present(alert, animated: true, completion: nil) self.isRecording = false } } func previewControllerDidFinish(_ previewController: RPPreviewViewController) { dismiss(animated: true) } }
Posted Last updated
.