首页 > 解决方案 > ReplayKit 在应用程序的后台模式或应用程序外部停止屏幕录制?

问题描述

我已经在应用程序的前台模式下使用 ReplayKit 实现了屏幕录制。但是当我使用主页按钮应用程序离开应用程序时,应用程序会停止后台记录。--> App Store 中有一个应用程序允许后台录屏。--> 如果我必须使用广播上传和 UI 扩展,那么请给我一些编程指南。我已经在我的应用程序中添加了两者,但它仍然停止在后台模式下录制。

下面是我的代码

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) {

    }
}
}

标签: iosswift4.2screen-recordingreplaykit

解决方案


推荐阅读