5
votes

I am using replay kit to save a video of my screen during gameplay but randomly on occasion startRecordingWithMicrophoneEnabled and recorder.stopRecordingWithHandler never enters the completion handler

it doesn't throw an error, it just runs and hangs indefinitely.

if recorder.available && recorder.microphoneEnabled {
    recorder.startRecordingWithMicrophoneEnabled(true) { [unowned self] (error) in
        if let unwrappedError = error {
            print(unwrappedError.localizedDescription)
        } else {
            print("called")
            self.manager.instructions.text = "Click to Start Game"
        }
    }
}

if recorder.available && recorder.microphoneEnabled {
    print("initiating stop recording")
    recorder.stopRecordingWithHandler { [unowned self] (RPPreviewViewController, error) in
        print("in completion handler")
        if let previewView = RPPreviewViewController {
            print("will transition to gameplay video")
            previewView.previewControllerDelegate = self
            self.presentViewController(previewView, animated: true, completion: nil)
            self.sessionHandler.session.stopRunning()
        }
    }
}
2
You need to check whether screen recorder and microphone is available before you call the startRecording. - Sachin Vas
i added it, but the problem persists - stanley
Please update the question with the above checks. - Sachin Vas
updated; please check it out - stanley
microphone available check isn't there. You need the microphone and check doesn't exists. - Sachin Vas

2 Answers

0
votes

I was getting this same thing. Was working on one device, and not on another. Only difference was the working device was on iOS version 10.1.0 and the other was iOS version 10.0.2 - upgraded to 10.2.0 and it started working immediately.

0
votes

I had the same problem and just found its cause (or maybe just a cause). If your device is connected to a WiFi that has no internet access this problem occurs. If you connect it to a WiFi that has internet access or disable WiFi it works just fine. I guess when starting a recording, ReplayKit tries to connect to some Apple servers but never reaches them and also never times out. You can observe the same behavior with the App Store. When you are connected to a WiFi without internet it tries to load the store forever and never times out.