Reputation: 562
I am trying to include recording functionality to my C++ based game with ReplayKit
. I check that the iOS version is 9.0 or above in my game code, and if it is, I will call RecordReplayIOS::startRecording()
and then the ReplayKit should start recording.
For some reason the startRecordingWithMicrophoneEnabled
function returns always an error -5803
, which according to API documentation means RPRecordingErrorFailedToStart
. Any ideas what I am doing wrong?
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
Upvotes: 3
Views: 1112
Reputation: 562
There is nothing wrong with the code. It seems that I just tried to use ReplayKit with an iPad which was too old. Apparently ReplayKit needs either A7 or A8 processor. My iPad 4 which has A6 processor simply does not work with ReplayKit.
The correct way to check if the device can use ReplayKit is to query RPScreenRecorder.sharedRecorder.available
. It returns true if the device supports ReplayKit.
Upvotes: 3