我想用目标Action Extension录制我的应用程序的屏幕、音频和视频。
如果我将此代码放在普通应用程序中,它可以工作,但在操作扩展中则不行。
@IBAction func recButton(_ sender: Any) {
if recButton.currentTitle == "stop" {
stopRecording()
recButton.setTitle("rec", for: .normal)
}
else {
recButton.setTitle("stop", for: .normal)
RPScreenRecorder.shared().isMicrophoneEnabled = true
RPScreenRecorder.shared().startRecording(handler: {[unowned self] (error) in
//Handler - never called
if let unwrappedError = error {
print(unwrappedError.localizedDescription)
}
})
}
}
func stopRecording() {
RPScreenRecorder.shared().stopRecording(handler: {(previewController, error) -> Void in
//Handler - never called
if previewController != nil {
let alertController = UIAlertController(title: "Recording", message: "Do you want to discard or view your recording?", preferredStyle: .alert)
let discardAction = UIAlertAction(title: "Discard", style: .default) { (action: UIAlertAction) in
RPScreenRecorder.shared().discardRecording(handler: { () -> Void in
// Executed once recording has successfully been discarded
})
}
let viewAction = UIAlertAction(title: "View", style: .default, handler: { (action: UIAlertAction) -> Void in
self.present(previewController!, animated: true, completion: nil)
})
alertController.addAction(discardAction)
alertController.addAction(viewAction)
self.present(alertController, animated: true, completion: nil)
} else {
// Handle error
}
})
}
是否有另一种方法可以使用 AVCaptureSession 来实现这一目标,还是我需要使用其他方法来实现这一目标?谢谢。