0

我正在使用 ReplayKit 录制屏幕,但是当我在模拟器中运行应用程序时,我无法停止它,并且没有预览录制的视频,但我在输出控制台中收到以下消息。

2016-07-27 23:46:35.196 replay1[65028:4134788] plugin com.apple.ReplayKit.RPVideoEditorExtension interrupted
2016-07-27 23:46:35.196 replay1[65028:4134989] Hub connection error Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named com.apple.ReplayKit.RPVideoEditorExtension" UserInfo={NSDebugDescription=connection to service named com.apple.ReplayKit.RPVideoEditorExtension}

所以我尝试在 iPhone 6s 上运行这个应用程序。

我收到有关如何在应用程序中录制的警报,但是当我尝试停止时,它不会停止并且控制台中有一条消息

2016-07-27 21:29:43.118 replay[3009:968481] -[UIWindow endDisablingInterfaceAutorotationAnimated:] called on <UIWindow: 0x14ce56570; frame = (0 0; 375 667); gestureRecognizers = <NSArray: 0x14ce573f0>; layer = <UIWindowLayer: 0x14ce55480>> without matching -beginDisablingInterfaceAutorotation. Ignoring.

此外,当我在应用程序中按下时stop,它不会变为start.

这是代码:

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

    func startRecording()
    {
        let recorder = RPScreenRecorder.sharedRecorder()

        recorder.startRecordingWithMicrophoneEnabled(true) { [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))
            }
        }
    }

    func stopRecording()
    {
        let recorder = RPScreenRecorder.sharedRecorder()

        recorder.stopRecordingWithHandler { [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.presentViewController(unwrappedPreview, animated: true, completion: nil)
            }
        }
    }

    func previewControllerDidFinish(previewController: RPPreviewViewController)
    {
        dismissViewControllerAnimated(true, completion: nil)
    }
}

我要去哪里/做错了什么?

谢谢。

PS 我刚开始 iOS 开发,所以我无法完全理解控制台中的消息在说什么。

4

2 回答 2

0

我从来没有让 replayKit 在模拟器中工作。我认为它依赖于硬件中的物理芯片来完成部分工作。

不过,我不确定您的错误的自动旋转部分。

于 2017-02-14T04:46:02.517 回答
0
//Replay kit doesn't work on simulator and will work on a physical device.

//Try this code hope it helps:

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

    if #available(iOS 9.0, *) {
        recorder.startRecording(withMicrophoneEnabled: true) { [unowned self] (error) in
            if let unwrappedError = error {
                print(unwrappedError.localizedDescription)
            } else {
                self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Stop", style: .plain, target: self, action: #selector(PreviewVC.stopRecording))
            }
        }
    } else {
        // Fallback on earlier versions
    }
}

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(PreviewVC.startRecording))

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

    func previewControllerDidFinish(_ previewController: RPPreviewViewController) {
        self.dismiss(animated: true, completion: nil)
    }
于 2017-08-18T06:47:53.220 回答