重播套件返回错误"RPRecordingErrorFailedToStart"

ReplayKit returns error "RPRecordingErrorFailedToStart"

本文关键字:RPRecordingErrorFailedToStart 错误 返回 套件      更新时间:2023-10-16

我正在尝试将录制功能添加到我的ReplayKit基于C++的游戏中。我在游戏代码中检查iOS版本是否为9.0或更高版本,如果是,我会调用RecordReplayIOS::startRecording(),然后ReplayKit应该开始录制。

由于某些原因,startRecordingWithMicrophoneEnabled函数总是返回错误-5803,根据API文档,这意味着RPRecordingErrorFailedToStart。你知道我做错了什么吗?

RecordReplayIOS.hpp:

#ifndef __RECORD_REPLAY_IOS_HPP__
#define __RECORD_REPLAY_IOS_HPP__
class RecordReplayIOS {
public:
    static bool canRecord();
    static void startRecording();
    static void stopRecording();
};
#endif

RecordReplayIOS.mm:

#include "RecordReplay_ios.hpp"
#include "ReplayKit/ReplayKit.h"
@interface Recorder : NSObject
+(void)startRecording;
+(void)stopRecording;
@end
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
bool RecordReplayIOS::canRecord() {
    // ReplayKit needs at least iOS 9
    if (SYSTEM_VERSION_LESS_THAN(@"9.0")) {
        return false;
    }
    return true;
}
void RecordReplayIOS::startRecording() {
    [Recorder startRecording];
}
void RecordReplayIOS::stopRecording() {
    [Recorder stopRecording];
}
@implementation Recorder
+(void)startRecording {
    RPScreenRecorder* recorder = RPScreenRecorder.sharedRecorder;
    recorder.delegate = self;
    [recorder startRecordingWithMicrophoneEnabled:false handler:^(NSError * error) {
        if(error != nil) {
            NSString* desc = error.description;
            return;
        }
    }];
}
+(void)stopRecording {
    RPScreenRecorder* recorder = RPScreenRecorder.sharedRecorder;
    [recorder stopRecordingWithHandler:^(RPPreviewViewController *previewViewController, NSError *error) {
        if(error != nil) {
            NSString* desc = error.description;
            return;
        }
        if(previewViewController) {
            //do stuff...    
        }
    }];
}
@end

代码没有任何问题。我似乎只是试着用一台太旧的iPad来使用ReplayKit。显然ReplayKit需要A7或A8处理器。我的iPad4有A6处理器,根本无法与ReplayKit配合使用。

检查设备是否可以使用ReplayKit的正确方法是查询RPScreenRecorder.sharedRecorder.available。如果设备支持ReplayKit,则返回true。

相关文章:
  • 没有找到相关文章