Replaykit Startrecording Sometimes Never Enters Completion Handler

ReplayKit: startRecording() completion handler is never entered

I guess I found the answer myself. Please try this out and and confirm if it works:

  1. Delete your App
  2. Clean Xcode project
  3. Hold power button of your iOS device
  4. When slide to turn off appears, hold home button until screen flashes black, then release all buttons
  5. Run your Xcode project again
  6. Handlers should now be called again

My suspicion is that there is some bug in the used shared instance of the recorder which can only be reset when cleaning up the device RAM.

Edit:
I also observed that this error only happens when I stop the running app with Xcode while the recording is in progress. If I put the app in the background or shut down the app with the iOS task manager, then this error does not appear when the app is started again.

Conclusion: DO NOT shut down your app using Xcode, while recording is running. If you use the iOS task manager instead then it will continue working properly and deliver the callbacks.

Edit 2:
A bug report is filed and Apple answered that they are aware of this problem, working on it to solve it.

Replaykit, startCaptureWithHandler() not sending CMSampleBufferRef of Video type in captureHandler

So, I have come across some scenarios where Replay kit totally crashes and System recorder shows error every time unless you restart the device.

1st Scenario

When you start recording and stop it in completion handler

[RPScreenRecorder.sharedRecorder startCaptureWithHandler:^(CMSampleBufferRef  _Nonnull sampleBuffer, RPSampleBufferType bufferType, NSError * _Nullable error) {
printf("recording");
} completionHandler:^(NSError * _Nullable error) {
[RPScreenRecorder.sharedRecorder stopCaptureWithHandler:^(NSError * _Nullable error) {
printf("Ended");
}];
}];

2nd Scenario

When you start recording and stop it directly in capture handler

__block BOOL stopDone = NO;
[RPScreenRecorder.sharedRecorder startCaptureWithHandler:^(CMSampleBufferRef _Nonnull sampleBuffer, RPSampleBufferType bufferType, NSError * _Nullable error) {
if (!stopDone){
[RPScreenRecorder.sharedRecorder stopCaptureWithHandler:^(NSError * _Nullable error) {
printf("Ended");
}];
stopDone = YES;
}
printf("recording");
} completionHandler:^(NSError * _Nullable error) {}];

More Scenarios are yet to be discovered and I will keep updating the
answer

Update 1

It is true that the system screen recorded gives error when we stop recording right after the start, but it seem to work alright after we call startcapture again.

I have also encountered a scenario where I don't get video buffer in my
app only and the system screen recorder works fine, will update the
solution soon.

Update 2

So here is the issue, My actual app is old and it is being maintained and getting updated timely. When the replaykit becomes erroneous, My original app can't receive video buffers, I don't know if there is a configuration that is making this happen, or what?

But new sample app seem to work fine and after replay kit becomes erroneous. when I call startCapture next time, the replay kit becomes fine.
Weird

Update 3

I observed new issue. When the permission alert shows up, the app goes to background. Since I coded that whenever the app goes to background, some UI changes will occur and the recording will be stopped.
This led to the error of

Recording interrupted by multitasking and content resizing

I am not yet certain, which particular UI change is creating this failure, but it only comes when permission alert shows up and the UI changes are made.
If someone has noticed any particular case for this issue, please let us know.



Related Topics



Leave a reply



Submit