如果没有出现权限弹出窗口,为什么即使启用了 RPScreenRecorder,它也不会录制麦克风?当弹出窗口出现时它可以工作,但重新启动应用程序后的尝试不会录制麦克风。 这是我制作的非常简单的应用程序,只是为了测试更大的应用程序的此功能。
我已经在 iOS 11 上测试了这个应用程序,它每次都能工作。然而,在 iOS 12+ 上,它仅在权限弹出窗口出现时才起作用,并且每 8 分钟出现一次。每次授予权限后都应该有效。
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)
}
}
我希望麦克风在允许权限后每次都应该录音,但它似乎只在请求这些权限的 session 期间录制麦克风。
最佳答案
这似乎已在 iOS 13 中修复。现在,每次您请求录制屏幕时,操作系统都会请求许可。但我仍然没有修复 iOS 12 的问题。
关于ios - RPScreenRecorder 在奇怪的情况下不录制麦克风,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57794860/