gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 15:58:57 24 4
gpt4 key购买 nike

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

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

#import <ReplayKit/ReplayKit.h>

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

然后在我的游戏 View 中,单击“录制”按钮以触发录制,如下所示:
- (void)StartRecording
{
RPScreenRecorder* recorder = RPScreenRecorder.sharedRecorder;
recorder.delegate = self;
[recorder startRecordingWithMicrophoneEnabled:YES handler:^(NSError *error) {

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

使用“stop_btn”停止录制屏幕:
- (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];
}

但是,当我触摸 '"Record"或 "Stop_btn"` 时,没有进入相应的处理程序。

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

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

最佳答案

要回答 Veslam 的问题,您可以这样做。假设您有自己的带有窗口属性的 AppDelegate:

@interface MyAppDelegate : NSObject <UIApplicationDelegate> 
{

}

@property (nonatomic, retain) UIWindow* myWindow;

在 MyAppDelegate.mm 文件中,您将像以前一样初始化 myWindow,可能在 didFinishLaunchingWithOptions 中。然后您必须为 AppDelegate 的 window 属性定义 setter,如下所示:
-(UIWindow*) window
{
// this is necessary so that ReplayKit can display its popup window
return myWindow;
}

这将在您尝试开始录制时修复“AppDelegate UIWindow:unrecognized selector to instance”错误。

关于ios - ReplayKit 在我的 Objective-C 代码中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32535123/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com