ReplayKit returns 错误 "RPRecordingErrorFailedToStart"
ReplayKit returns error "RPRecordingErrorFailedToStart"
我正在尝试使用 ReplayKit
将录制功能添加到我的基于 C++ 的游戏中。我在我的游戏代码中检查 iOS 版本是否为 9.0 或更高版本,如果是,我将调用 RecordReplayIOS::startRecording()
然后 ReplayKit 应该开始录制。
出于某种原因,startRecordingWithMicrophoneEnabled
函数 returns 总是一个错误 -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 处理器。我的 iPad 4 配备 A6 处理器,但无法与 ReplayKit 一起使用。
检查设备是否可以使用ReplayKit的正确方法是查询RPScreenRecorder.sharedRecorder.available
。如果设备支持 ReplayKit,它 returns 为真。
我正在尝试使用 ReplayKit
将录制功能添加到我的基于 C++ 的游戏中。我在我的游戏代码中检查 iOS 版本是否为 9.0 或更高版本,如果是,我将调用 RecordReplayIOS::startRecording()
然后 ReplayKit 应该开始录制。
出于某种原因,startRecordingWithMicrophoneEnabled
函数 returns 总是一个错误 -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 处理器。我的 iPad 4 配备 A6 处理器,但无法与 ReplayKit 一起使用。
检查设备是否可以使用ReplayKit的正确方法是查询RPScreenRecorder.sharedRecorder.available
。如果设备支持 ReplayKit,它 returns 为真。