0
votes

I'm using ReplayKit to record the screen but when I run the app in the simulator I cant stop it and there is no preview of the recorded video but I'm getting following message in the output console.

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}

So I tried to run the app on the iPhone 6s itself.

I'm getting an alert about how to record in the app but when I tried to stop, it wont stop and there is a message in the console

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.

Also, when I press stop in the app, it won't change to start.

Here is the code:

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

Where I am going/doing wrong?

Thanks.

P.S I just started iOS development so I can't completely understand what that message in the console is saying.

2
I'm getting your second alert message while running on a device. Everything is working fine though it's printing out this error. Can you remember if you were able to fix the problem? - Waylan Sands

2 Answers

0
votes

I've never been able to get replayKit to work in the simulator. I think it relies on the physical chip in the hardware to do some part of the work.

I'm not sure about the auto-rotation part of your error though.

0
votes
//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)
    }