我正在尝试使用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

最佳答案

代码没有错。看来我只是尝试将ReplayKit与太旧的iPad一起使用。显然ReplayKit需要A7或A8处理器。我的具有A6处理器的iPad 4根本无法与ReplayKit一起使用。

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

09-12 09:23