Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make it work with NSURLConnection #69

Closed
gdubs opened this issue Jun 5, 2013 · 5 comments
Closed

How to make it work with NSURLConnection #69

gdubs opened this issue Jun 5, 2013 · 5 comments

Comments

@gdubs
Copy link

gdubs commented Jun 5, 2013

So I've been trying to make it work with my app that uses NSURLConnection to call my APIs, and it's just now (after 3 days and comparing the PDTwitter example) that I realized the example project uses AFnetworking and that kinda affects if the requests get detected.

I basically tried changing (as a test) the one I used from NSURLconnection to ASJSonRequestOperation. Before it would see my app on the listener but will not list anything on the Network tab, now it would show details regarding the request.

Basically my question is, I'm not sure if the NSURLConnection that I used was wrong that's why it wasn't detected or if PonyDebugger just chooses to detect AFNetworking methods only?

I hope my question makes sense.

Thanks!

@wlue
Copy link
Contributor

wlue commented Jun 5, 2013

PonyDebugger should work out of the box with NSURLConnection. The reason it works with AFNetworking is because it uses NSURLConnection internally. Can you show me how you're using it, and also how you're integrating PonyDebugger? (make sure you call [debugger forwardAllNetworkTraffic];).

@gdubs
Copy link
Author

gdubs commented Jun 5, 2013

Apologies for the late reply, I was at work. But yes I have these on my appdelegate.m which I copied from the twitter example

//#if ENABLE_PONYDEBUGGER
PDDebugger *debugger = [PDDebugger defaultInstance];

// Enable Network debugging, and automatically track network traffic that comes through any classes that NSURLConnectionDelegate methods.
[debugger enableNetworkTrafficDebugging];
[debugger forwardAllNetworkTraffic];

// Enable Core Data debugging, and broadcast the main managed object context.
[debugger enableCoreDataDebugging];
//[debugger addManagedObjectContext:self.managedObjectContext withName:@"Twitter Test MOC"];

// Enable View Hierarchy debugging. This will swizzle UIView methods to monitor changes in the hierarchy
// Choose a few UIView key paths to display as attributes of the dom nodes
[debugger enableViewHierarchyDebugging];
[debugger setDisplayedViewAttributeKeyPaths:@[@"frame", @"hidden", @"alpha", @"opaque", @"accessibilityLabel", @"text"]];

// Connect to a specific host
[debugger connectToURL:[NSURL URLWithString:@"ws://localhost:9000/device"]];
// Or auto connect via bonjour discovery
//[debugger autoConnect];
// Or to a specific ponyd bonjour service
//[debugger autoConnectToBonjourServiceNamed:@"MY PONY"];

// Enable remote logging to the DevTools Console via PDLog()/PDLogObjects().
[debugger enableRemoteLogging];
//#endif

This is how I call my POST using NSURLConnection btw:

NSDictionary *jsonRequestDictionary = [NSDictionary dictionaryWithObjects:requestValues forKeys:requestKeys];
NSError *error = nil;
NSData *jsonRequest = [NSJSONSerialization dataWithJSONObject:jsonRequestDictionary options:NSJSONWritingPrettyPrinted error:&error];

NSString *urlStringRequest = [NSString stringWithFormat:@"blaapi/%@/b/%@/m/%@?%@", self.eid, self.bid, self.Id, [WCFServiceRequest getauth]];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlStringRequest]];

[request setHTTPMethod:@"POST"];
[request setHTTPBody:jsonRequest];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d", [jsonRequest length]] forHTTPHeaderField:@"Content-Length"];


NSHTTPURLResponse *response = nil;
NSData *reqData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

@ehlersd
Copy link

ehlersd commented Aug 3, 2013

I'm seeing the same thing here. My guess is that using the static "sendSynchronousRequest" method which uses blocks bypasses the delegate process, which is what is used to hook into and monitor the communications.

I'm pretty sure in this case the easy solution is to not use this static function.

@ehlersd
Copy link

ehlersd commented Aug 3, 2013

Just as a solution, I wrote a DNURLConnection class that makes it easy to replace the sendAsynchronousRequest with delegate functions....with only a single line change.

https://github.com/ehlersd/DNURLConnection

Just replace this line:

[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {}];

with this line:

[DNURLConnection connectionWithRequest:request completionHandler:^(NSURLResponse *response, NSData *data, NSError *error){}];

@NickEntin
Copy link
Collaborator

We're doing some housecleaning, so I'm going to close this issue since a solution has been proposed. Please reopen if this is still a problem. Thanks.

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

No branches or pull requests

4 participants