HTTP 요청을 스텁하기 위해 OHHTTPStubs를 사용하고 있으며 AFHetworking에서 생성 한 트래픽을 기록하기 위해 SWHttpTrafficRecorder를 사용하려고합니다. 몇 가지 이유로 트래픽 레코더에 AFNetworking AFHTTPSessionManager에서 생성 된 트래픽을 기록 할 수 없습니다. 구성 및 모든 전달하지만 모든 파일을 만들거나 모든 웹 요청을 만드는 인식하지 못합니다. 다음은 레코더를 실행하기위한 코드입니다.SWHttpTrafficRecorder AFNetworking 3.0 호환성
NSError *e;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *bpdDir = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"BPDTests"];
NSLog(@"setting up traffic recorder");
self.recorder = [SWHttpTrafficRecorder sharedRecorder];
__weak BPDKAPIClient_Tests *weakSelf = self;
// This block determines the name that will be given to the file generated
// by each http request
self.recorder.fileNamingBlock = ^NSString*(NSURLRequest *request, NSURLResponse *response, NSString *defaultName)
{
NSString *name = [weakSelf fileNameForRequest:request];
NSLog(@"new name: %@, default name: %@", name, defaultName);
return name;
};
// This block determines if we will record the http request
self.recorder.recordingTestBlock = ^BOOL(NSURLRequest *request)
{
NSString *path = [weakSelf filePathForRequest:request];
NSLog(@"are we deciding to record?");
(![[NSFileManager defaultManager] fileExistsAtPath:path]) ? NSLog(@"Yes") : NSLog(@"No");
return ![[NSFileManager defaultManager] fileExistsAtPath:path];
};
// This line forces the singleton configuration to initialize it's session manager and by extension the session
// configuration. This way we can actually pass in the configuration to the recorder
__unused AFHTTPSessionManager *m = self.apiClient.apiClientConfig.httpSessionManager;
NSLog(@"config passed in: %@", self.apiClient.apiClientConfig.httpSessionManagerConfiguration);
[self.recorder startRecordingAtPath:bpdDir
forSessionConfiguration:self.apiClient.apiClientConfig.httpSessionManagerConfiguration
error:&e];
if (e)
{
NSLog(@"error recording: %@", e);
}
누구나 SWTrafficRecorder와 AFNetworking 3.0이 호환되는지 알고 있습니까? 그렇다면 내 요청이 레코더가 아닌 이유는 무엇입니까? 그렇지 않다면 AFNetworking의 http 트래픽을 기록하기 위해 다른 라이브러리를 사용할 수 있습니까?