-->

ReplayKit stops screen recording in background mod

2019-05-16 21:54发布

问题:

I've implemented screen recording with ReplayKit in foreground mode of the application. But when I'm going outside the app with home button app stops background record. --> There is an app available In App Store which allows background screen record. --> If I have to use Broadcast upload and UI extension then please provide me some programming guide. I've added both in my app but still it stops recording in background mode.

Below is my code

import UIKit
import ReplayKit

class ViewController: UIViewController {

let recorder = RPScreenRecorder.shared()

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

@IBAction func btnStartRecord_Action(_ sender: UIButton) {
    if recorder.isAvailable {
        if !recorder.isRecording {
            recorder.startRecording { (error) in
                if let error = error {
                    print(error)
                }
            }
        }
    }
}

@IBAction func btnStopRecord_Action(_ sender: UIButton) {
    if recorder.isAvailable {
        if recorder.isRecording {
            recorder.stopRecording { (previewVC, error) in
                if let previewController = previewVC {
                    previewController.previewControllerDelegate = self
                    self.present(previewController, animated: true, completion: nil)
                }
            }
        }
    }
}
}

extension ViewController: RPPreviewViewControllerDelegate {
func previewControllerDidFinish(_ previewController: RPPreviewViewController) {
    previewController.dismiss(animated: true) {

    }
}
}