ios 如何记录不仅是应用程序的屏幕,但在屏幕上的一切,包括其他应用程序

vqlkdk9b  于 2023-04-08  发布在  iOS
关注(0)|答案(2)|浏览(207)

我试图使用ReplayKit实现屏幕录制应用程序(Swift).它似乎当我去应用程序外,停止后台记录.在尝试了一些文件,到目前为止,我明白我需要实现广播扩展.如果我的理解是正确的,那么所以请给予我一些编程指南.

xu3bshqb

xu3bshqb1#

试试这个图书馆
Screen capture
或者这个:
Vid recorder

import ScreenCapture

let recorder = ScreenCapture.recordScreen("/path/to/save/to.mp4")

recorder.start()
...
recorder.stop()

let movieUrl = recorder.destination

否则,您可以执行:

import ReplayKit
import UIKit

class ViewController: UIViewController, RPPreviewViewControllerDelegate {
    override func viewDidLoad() {
        super.viewDidLoad()

        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Start", style: .plain, target: self, action: #selector(startRecording))
    }

    @objc func startRecording() {
        let recorder = RPScreenRecorder.shared()

        recorder.startRecording{ [unowned self] (error) in
            if let unwrappedError = error {
                print(unwrappedError.localizedDescription)
            } else {
                self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Stop", style: .plain, target: self, action: #selector(self.stopRecording))
            }
        }
    }

    @objc func stopRecording() {
        let recorder = RPScreenRecorder.shared()

        recorder.stopRecording { [unowned self] (preview, error) in
            self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Start", style: .plain, target: self, action: #selector(self.startRecording))

            if let unwrappedPreview = preview {
                unwrappedPreview.previewControllerDelegate = self
                self.present(unwrappedPreview, animated: true)
            }
        }
    }

    func previewControllerDidFinish(_ previewController: RPPreviewViewController) {
        dismiss(animated: true)
    }
}

重播工具包只记录它的当前应用程序屏幕,每当应用程序成为背景,记录将被停止,这是由设计。

qgelzfjb

qgelzfjb2#

您需要实现广播扩展。流程如下:
1.创建一个新的Xcode项目
1.导入ReplayKit
1.在情节提要中添加UIView,并在情节提要Identity Inspector中将其类更改为RPSystemBroadcastPickerView
1.文件〉新建〉目标〉广播上传扩展

  1. Xcode〉Project Navigator〉Targets〉Select Extension〉General〉Change Deployment Info〉Match with your main project
    1.点击步骤3中创建的视图应弹出广播视图。

相关问题