简体   繁体   中英

RPScreenRecorder How recording screen audio and video of an app Action Extension?

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:

In iOS, an Action extension:

  • Helps users view the current document in a different way
  • Always appears in an action sheet or full-screen modal view
  • Receives selected content only if explicitly provided by the host app

Not quite sure how a screen recording would fit into that pattern in a way that convinces Apple...

I don't think that this is not possible, as I have seen some apps on App Store, which are recording video and Audio within iMessage extension app. Like : SuperMoji App This app records face expression and audio and sends as a video message within iPhone's Message app only.

However, I am not sure how to do that in Extension apps. I am working on it and will let you know very soon.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM