如果没有出现权限弹出窗口,为什么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)
}
}我希望麦克风在允许权限后每一次都应该录制,但它似乎只在请求这些权限的会话期间录制麦克风。
发布于 2019-09-20 02:24:05
这个问题似乎已经在iOS 13中得到了解决。现在,每当你请求录制屏幕时,操作系统都会请求许可。然而,我仍然没有解决iOS 12的问题。
https://stackoverflow.com/questions/57794860
复制相似问题