在Unity 5.3.4中使用iOS ReplayKit时,通过自定义插件无法解散PreviewViewControll

本文关键字:插件 自定义 PreviewViewControll Unity ReplayKit iOS | 更新日期: 2023-09-27 18:06:57

我正在尝试使用ReplayKit的本机屏幕录制功能以及我的Unity应用程序,以便我可以享受本机屏幕录制和共享UI的好处。

我已经创建了一个Unity插件,它调用我用Objective-C(++)编写的本地代码,一切似乎都工作得很好,直到它来驳回RPPreviewViewController

所以我的记录按钮在Unity UI触发ReplayKit startRecordingWithMicrophoneEnabled:handler函数和停止按钮正确调用stopRecording函数返回RPPreviewViewController实例到我的处理程序。

RPPreviewViewController中,"保存"按钮正确保存到相机卷,共享按钮按预期工作。但是点击"取消"(或"完成"取决于上下文)没有任何作用。

以下是我的stopRecordingWithHandler:函数中的代码,该函数处理RPPreviewViewController:

 - (void) stopRecording {
     [[RPScreenRecorder sharedRecorder] stopRecordingWithHandler:^(RPPreviewViewController *previewController,NSError *error){
     if (previewController != nil) {
         previewController.previewControllerDelegate = self;
         [previewController willMoveToParentViewController:rootView];
         [rootView addChildViewController:previewController];
         previewController.view.frame = CGRectMake(0.0, 0.0, rootView.view.bounds.size.width, rootView.view.bounds.size.height);
         [rootView.view addSubview:previewController.view];
         self.presentedController = previewController;
     } else {
         NSString *msg = [NSString stringWithFormat:@"The screen recorder is unavailable:'n%@", [error localizedDescription]];
         [self displayMessageDialog:msg];
     }
 }];
}
// Implementation of PreviewControllerDelegate protocol
- (void)previewControllerDidFinish:(RPPreviewViewController *)previewController {
    [previewController willMoveToParentViewController:nil];
    [previewController.view removeFromSuperview];
    [previewController removeFromParentViewController];
    self.presentedController = nil;
}

正如你所看到的,我已经为RPPreviewViewControllerDelegate实现了协议,并试图在其关闭事件时解散视图,但委托函数从未被调用。

我不知道是什么错了,是我写错了代码,还是在使用Unity时存在复杂性?

我卡住了,所以任何指示将非常感激!

更新:上面的代码中使用了rootView,所以下面是我如何在init函数中检索该引用:

static UIViewController *rootView;
- (ReplayKitController*) init {
    self = [super init];
    if(self && rootView == nil) {
        rootView = [[UIApplication sharedApplication] windows][0].rootViewController;
    }
    return self;
}

在Unity 5.3.4中使用iOS ReplayKit时,通过自定义插件无法解散PreviewViewControll

在尝试了一些事情之后,我终于对它进行了排序,但我认为问题是我如何使用

设置previewControllerDelegate
previewController.previewControllerDelegate = self;

然后改成了

[previewController setPreviewControllerDelegate:self];

这似乎工作!

感谢所有查看我的问题的人,我希望这对那里的人有所帮助!