Skip to content
This repository has been archived by the owner on Jul 27, 2019. It is now read-only.

Not working with AFNetworking 3.0 #13

Open
Amindv1 opened this issue Dec 10, 2016 · 1 comment
Open

Not working with AFNetworking 3.0 #13

Amindv1 opened this issue Dec 10, 2016 · 1 comment

Comments

@Amindv1
Copy link

Amindv1 commented Dec 10, 2016

Does this pod not work with AFNetworking 3.0? I'm not able to get it to work. I'm passing in the NSURLSessionConfiguration I'm using to create a AFHTTPSessionManager but no files are ever created. Here's the code i use to setup the recorder:

`
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?");
            
    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);
}`
@Amindv1
Copy link
Author

Amindv1 commented Dec 19, 2016

I wanted to point out that this might be because I use this with OHHTTPStubs, both pods attempt to register a protocol class so one of them wont be working, this is most likely why this wasn't working at the time. It should be noted in the documentation that this pod isn't compatible with pods that register a custom URLProtocol.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant