I would like to record the screen, audio, and video of my app with target Action Extension.
If I put this code in a normal app, it works, but in an Action Extension doesn't.
@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
}
})
}
Is there another method to achieve this goal using AVCaptureSession, or do I need to use something else to achieve this? Thanks.
I'm pretty sure Apple won't let you do that by design. When it comes to extensions, they are generally very strict both in terms of what is allowed api-wise and what will pass app review.
Even if you figure out a hacky solution to overcome the issues with ReplayKit, I guess it would get rejected by app review.
In the general App Review Guidelines, the app extension programming guide is referenced as a defining guideline where for action extension it specifically says:
Not quite sure how a screen recording would fit into that pattern in a way that convinces Apple...