ReplayKit: startRecording() completion handler is never entered
I guess I found the answer myself. Please try this out and and confirm if it works:
- Delete your App
- Clean Xcode project
- Hold power button of your iOS device
- When slide to turn off appears, hold home button until screen flashes black, then release all buttons
- Run your Xcode project again
- 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 saving video fails first try with mic
Added retry logic to circumvent the issue. Not the greatest solution but it works.
[self.screenRecorder startCaptureWithHandler:^(CMSampleBufferRef _Nonnull sampleBuffer, RPSampleBufferType bufferType, NSError * _Nullable error) {
if(CMSampleBufferDataIsReady(sampleBuffer) == false || self.assetWriter == nil)
{
return;
}
if (self.assetWriter.status == AVAssetWriterStatusFailed) {
NSLog(@"AVWriter Failed!");
return;
}
if (CMSampleBufferDataIsReady(sampleBuffer)) {
if(self.assetWriter.status == AVAssetWriterStatusWriting) {
if (bufferType == RPSampleBufferTypeVideo) {
if (!self.startedSession) {
dispatch_async(dispatch_get_main_queue(), ^{
_startDate = [NSDate date];
_recordingTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateRecordingTime) userInfo:nil repeats:YES];
// Disable the idle timer while recording
[UIApplication sharedApplication].idleTimerDisabled = YES;
});
CMTime pts = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
[self.assetWriter startSessionAtSourceTime:pts];
self.startedSession = YES;
NSLog(@"MP4Writer: started session in appendVideoSample");
}
if (CMTimeCompare(kCMTimeInvalid, self.firstVideoFrameTime) == 0) {
self.firstVideoFrameTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
}
if (self.assetWriterVideoInput.readyForMoreMediaData) {
@try {
[self.assetWriterVideoInput appendSampleBuffer:sampleBuffer];
}
@catch(NSException *expection) {
NSLog(@"Missed Video Buffer: %@", self.assetWriter.error);
}
}
}
if (bufferType == RPSampleBufferTypeAudioMic) {
if (CMTimeCompare(kCMTimeInvalid, self.firstVideoFrameTime) == 0 ||
CMTimeCompare(self.firstVideoFrameTime, CMSampleBufferGetPresentationTimeStamp(sampleBuffer)) == 1) {
return;
}
if (!self.startedSession) {
CMTime pts = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
[self.assetWriter startSessionAtSourceTime:pts];
self.startedSession = YES;
NSLog(@"MP4Writer: started session in appendAudioSample");
}
if (self.assetWriterAudioInput.isReadyForMoreMediaData) {
@try {
[self.assetWriterAudioInput appendSampleBuffer:sampleBuffer];
}
@catch(NSException *expection) {
NSLog(@"Missed Audio Buffer: %@", self.assetWriter.error);
}
}
}
}
}
} completionHandler:^(NSError * _Nullable error) {
if (!error) {
NSLog(@"Recording started successfully.");
}
}];
App not showing up as a broadcast service in RPBroadcastActivityViewController
Had to add the Broadcast Extension, in Xcode, File -> New -> Target -> Broadcast Upload Extension. This extension was then displayed in the picker.
ReplayKit's RPSystemBroadcastPickerView not showing preferredExtension
I think it is the apple's bug, but it was fixed in iOS 12.2 after I tested it.
Related Topics
Fbsdk (New Facebook Sdk 4.0) Implementation Is Not Working for Login with Facebook
iOS Uiimagepickercontroller: Any Way of Getting the Date of the Chosen Picture
Please Add the Host Targets for the Embedded Targets to the Podfile
How to Change How a Remote Notification Is Presented Before Presentation
Swift 3 Filter Array of Dictionaries by String Value of Key in Dictionary
Get Light or Dark Variant of a Color Declared in Assets
Get the Exact Difference Between 2 Dates for a Single Nsdatecomponent
Showing Hidden View Really Slow
Invert Calayer Mask That Is Based on a Stroke (No Fill)
Multiple Cells Selected on Scrolling [Reuse Cells Problem]
Schedule Local Notification Every N Days (Timezone Safe)
Add View as a Parameter to a Custom Viewmodifier
Pausing Timer When App Is in Background State Swift
Using Huffman Coding to Compress Images Taken by the iPhone Camera
Replace C Style For-Loop in Swift 2.2.1