ReplayKit在我的Objective-C代码中不起作用

时间:2015-09-12 04:21:43

标签: ios ios9

有没有人知道如何在Objective-C中使用ReplayKit?

要在我的代码中使用ReplayKit,请按照我的RPScreenRecoderDelegate中的RPPreviewViewControllerDelegate appDelegate api实现。

#import <ReplayKit/ReplayKit.h>

@interface AppDelegate : NSObject <UIApplicationDelegate,
                                    NSURLConnectionDelegate,
                                    UIAlertViewDelegate,
                                    MFMailComposeViewControllerDelegate,
                                    RPPreviewViewControllerDelegate,
                                    RPScreenRecorderDelegate>
{}

然后在我的游戏视图中,我点击了我的&#34;记录&#34;按钮触发录音,就像这样:

- (void)StartRecording
{
    RPScreenRecorder* recorder =  RPScreenRecorder.sharedRecorder;
    recorder.delegate = self;
    [recorder startRecordingWithMicrophoneEnabled:YES handler:^(NSError *error) {

        if(error)
        {
            [self ShowRecordAlert:error.localizedDescription];
        }
    }];
}

使用&#34; stop_btn&#34;停止录制屏幕:

- (void)StopRecording
{
    RPScreenRecorder* recorder = RPScreenRecorder.sharedRecorder;

    [recorder stopRecordingWithHandler:^(RPPreviewViewController * previewViewController, 
NSError * error) {

        if(error)
        {
            [self ShowRecordAlert:error.localizedDescription];
        }

        if(previewViewController)
        {
            previewViewController.previewControllerDelegate = self;

            TiIOSDevice* device = (TiIOSDevice*)Game::Get()->GetDevice();
            UIViewController* con = (UIViewController*)device->GetViewController();

            previewViewController.modalPresentationStyle = UIModalPresentationFullScreen;

            [con presentViewController:previewViewController animated:YES completion:nil];
        }

    }];
}


//Implements two callbacks to capture the error:

- (void)screenRecorder:(RPScreenRecorder *)screenRecorder
            didStopRecordingWithError:(NSError *)error
            previewViewController:(RPPreviewViewController *)previewViewController
{
    if(error)
    {
        [self ShowRecordAlert:error.localizedDescription];
    }
}

- (void)previewControllerDidFinish:(RPPreviewViewController *)previewController
{
    [previewController dismissViewControllerAnimated:YES completion:nil];
}

然而,当我触及&#39;&#34;记录&#34;或&#34; Stop_btn&#34;`,相应的处理程序未输入。

我打印sharedRecorder.recording值和sharedRecorder.microphoneEnable值,它们都返回false。

我不知道丢失了哪一步,请给我一些建议。

1 个答案:

答案 0 :(得分:3)

要回答Veslam的问题,请按照以下方式进行操作。假设您有自己的AppDelegate窗口属性:

@interface MyAppDelegate : NSObject <UIApplicationDelegate> 
{

}

@property (nonatomic, retain) UIWindow* myWindow;

在MyAppDelegate.mm文件中,您可以像以前一样初始化myWindow,也许在didFinishLaunchingWithOptions中。然后你必须为AppDelegate的窗口属性定义setter,如下所示:

-(UIWindow*) window
{
  // this is necessary so that ReplayKit can display its popup window
  return myWindow;
}

这将修复&#34; AppDelegate UIWindow:无法识别的选择器到实例&#34;尝试开始录制时出错。