ReplayKit not working in Unity3D

Hi


Replaykit seems to not work on iOS11 apps build with Unity3D. Unity argues that they use Apple's native implementation, which brings me here. So is it correct that Replaykit is not stable on iOS11?


My implementation is basically:



public void recordVideo(){
         if (!ReplayKit.APIAvailable)
         {
             Debug.Log ("No ReplayKit found");
             }
         if (!isOn) {
        
             isOn = true;
             ShownPreviewScreen = false;
             ReplayKit.StartRecording();
             LedLight.SetActive (true);
 
     
         } else {
             Debug.Log ("Stop recording");
             ReplayKit.StopRecording();
             LedLight.SetActive (false);
             isOn = false;
             ReplayKit.Preview ();
 
             }
}

Replies

Unity's compiled code isn't the best though

It uses deprecated functions, and because it's Mono unless you're calling your code inside a ui capture block (button press) there's a high chance you're calling a UI operation on a background thread.


In your Unity generated objective c++ file (UnityReplayKit.mm) change the following function

- (BOOL)startRecording:(BOOL)enableMicrophone

{

RPScreenRecorder* recorder = [RPScreenRecorder sharedRecorder];

if (recorder == nil)

{

_lastError = [NSString stringWithUTF8String: "Failed to get Screen Recorder"];

return NO;

}



recorder.delegate = self;

__block BOOL success = YES;

[recorder startRecordingWithHandler:^(NSError* error) {

// [recorder startRecordingWithMicrophoneEnabled: enableMicrophone handler:^(NSError* error) {

if (error != nil)

{

_lastError = [error description];

success = NO;

}

else

{

dispatch_async(dispatch_get_main_queue(), ^{

[self createOverlayWindow];

});

}

}];



return success;

}

That fix doesn't work, I've just tried it. The only thing it changed is that now it asks for permission when I call the StartRecording method (it didn't even do that before). But I still don't get any video saved (I guess nothing is recorded).

Yes, there is an issue in iOS 11 with ReplayKit: sometimes the completion handler in stopRecording method is not called. When will Apple fix it? We don't know...