11// AFHTTPClientLogger.m
22//
3- // Copyright (c) 2012 Jon Parise
3+ // Copyright (c) 2012-2015 Jon Parise
44//
55// Permission is hereby granted, free of charge, to any person obtaining a copy
66// of this software and associated documentation files (the "Software"), to deal
2121// THE SOFTWARE.
2222
2323#import " AFHTTPClientLogger.h"
24- # import " AFHTTPRequestOperation.h "
25- #import " AFJSONRequestOperation.h "
24+
25+ #import < AFNetworking/AFHTTPRequestOperation.h >
2626
2727#import < objc/runtime.h>
2828
@@ -86,9 +86,8 @@ - (void)operationDidStart:(NSNotification *)notification {
8686
8787 id body = nil ;
8888 if ([operation.request HTTPBody ] && self.level <= AFHTTPClientLogLevelVerbose) {
89- if ([operation isKindOfClass: [AFJSONRequestOperation class ]]) {
90- body = [NSJSONSerialization JSONObjectWithData: [operation.request HTTPBody ] options: NSJSONReadingAllowFragments error: nil ];
91- } else {
89+ body = [NSJSONSerialization JSONObjectWithData: [operation.request HTTPBody ] options: NSJSONReadingAllowFragments error: nil ];
90+ if (body == nil ) {
9291 body = [[NSString alloc ] initWithData: [operation.request HTTPBody ] encoding: NSUTF8StringEncoding];
9392 }
9493 }
@@ -131,7 +130,6 @@ - (void)operationDidFinish:(NSNotification *)notification {
131130 }
132131
133132 NSURL *URL = (operation.response ) ? [operation.response URL ] : [operation.request URL ];
134- id responseObject = ([operation isKindOfClass: [AFJSONRequestOperation class ]]) ? ((AFJSONRequestOperation *)operation).responseJSON : operation.responseString ;
135133
136134 if (operation.error ) {
137135 switch (self.level ) {
@@ -148,14 +146,14 @@ - (void)operationDidFinish:(NSNotification *)notification {
148146 switch (self.level ) {
149147 case AFHTTPClientLogLevelDebug:
150148 if (operation.responseString ) {
151- NSLog (@" << %ld %@ \n %@ \n %@ " , (long )[operation.response statusCode ], [URL absoluteString ], [operation.response allHeaderFields ], responseObject);
149+ NSLog (@" << %ld %@ \n %@ \n %@ " , (long )[operation.response statusCode ], [URL absoluteString ], [operation.response allHeaderFields ], operation. responseObject );
152150 } else {
153151 NSLog (@" << %ld %@ \n %@ " , (long )[operation.response statusCode ], [URL absoluteString ], [operation.response allHeaderFields ]);
154152 }
155153 break ;
156154 case AFHTTPClientLogLevelVerbose:
157155 if (operation.responseString ) {
158- NSLog (@" << %ld %@ \n %@ " , (long )[operation.response statusCode ], [URL absoluteString ], responseObject);
156+ NSLog (@" << %ld %@ \n %@ " , (long )[operation.response statusCode ], [URL absoluteString ], operation. responseObject );
159157 } else {
160158 NSLog (@" << %ld %@ " , (long )[operation.response statusCode ], [URL absoluteString ]);
161159 }
@@ -173,7 +171,7 @@ - (void)operationDidFinish:(NSNotification *)notification {
173171
174172#pragma mark -
175173
176- @implementation AFHTTPClient (Logging)
174+ @implementation AFHTTPRequestOperationManager (Logging)
177175
178176static char AFHTTPClientLoggerObject;
179177
0 commit comments