ReplayKit returns error “RPRecordingErrorFailedToStart”

ⅰ亾dé卋堺 提交于 2019-12-10 22:55:01

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/33613763/replaykit-returns-error-rprecordingerrorfailedtostart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!