我想用目标动作扩展记录我的应用程序的屏幕、音频和视频。
如果我把这些代码放在一个普通的应用程序中,它就能工作,但是在Action扩展中却不能。
@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来实现这一目标,或者我是否需要使用其他方法来实现这个目标?谢谢。
发布于 2018-03-01 19:52:02
发布于 2018-04-05 07:28:21
我不认为这是不可能的,因为我在apps上看到了一些应用程序,它们在iMessage扩展应用程序中录制视频和音频。比如:SuperMoji应用程序,这个应用程序只记录面部表情和音频,并在iPhone的消息应用程序中作为视频消息发送。
但是,我不知道如何在扩展应用程序中做到这一点。我正在做这件事,很快会告诉你的。
https://stackoverflow.com/questions/48735074
复制相似问题