有人知道如何在Objective-C中使用ReplayKit吗?
为了在我的代码中使用ReplayKit,我遵循在我的appDelegate中实现RPScreenRecoderDelegate,RPPreviewViewControllerDelegate的api。
#import <ReplayKit/ReplayKit.h>
@interface AppDelegate : NSObject <UIApplicationDelegate,
NSURLConnectionDelegate,
UIAlertViewDelegate,
MFMailComposeViewControllerDelegate,
RPPreviewViewControllerDelegate,
RPScreenRecorderDelegate>
{}然后在我的游戏视图中,我点击我的“记录”按钮来触发记录,像这样:
- (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"`时,没有输入相应的处理程序。
我输出false值和sharedRecorder.microphoneEnable值,它们都返回false。
我不知道哪一步走错了,请给我一些建议。
发布于 2016-04-04 01:58:17
为了回答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:无法识别的选择器到实例“错误,当您尝试开始录制时。
发布于 2015-09-14 12:05:17
这个问题昨天已经解决了。appDelegate必须保留一个UIWindow实例,否则它将抛出异常:
appDelegate UIWindow:无法识别的实例
选择器
https://stackoverflow.com/questions/32535123
复制相似问题