File tree 2 files changed +18
-2
lines changed
2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change 1
- github "Alamofire/Alamofire" ~> 4.0
1
+ github "Alamofire/Alamofire" ~> 4.2
Original file line number Diff line number Diff line change @@ -141,7 +141,8 @@ public class NetworkActivityLogger {
141
141
}
142
142
143
143
@objc private func networkRequestDidComplete( notification: Notification ) {
144
- guard let userInfo = notification. userInfo,
144
+ guard let sessionDelegate = notification. object as? SessionDelegate ,
145
+ let userInfo = notification. userInfo,
145
146
let task = userInfo [ Notification . Key. Task] as? URLSessionTask ,
146
147
let request = task. originalRequest,
147
148
let httpMethod = request. httpMethod,
@@ -184,6 +185,21 @@ public class NetworkActivityLogger {
184
185
for (key, value) in response. allHeaderFields {
185
186
print ( " \( key) : \( value) " )
186
187
}
188
+
189
+ guard let data = sessionDelegate [ task] ? . delegate. data else { break }
190
+
191
+ do {
192
+ let jsonObject = try JSONSerialization . jsonObject ( with: data, options: . mutableContainers)
193
+ let prettyData = try JSONSerialization . data ( withJSONObject: jsonObject, options: . prettyPrinted)
194
+
195
+ if let prettyString = String ( data: prettyData, encoding: . utf8) {
196
+ print ( prettyString)
197
+ }
198
+ } catch {
199
+ if let string = NSString ( data: data, encoding: String . Encoding. utf8. rawValue) {
200
+ print ( string)
201
+ }
202
+ }
187
203
case . info:
188
204
print ( " \( String ( response. statusCode) ) ' \( requestURL. absoluteString) ' [ \( String ( format: " %.04f " , elapsedTime) ) s] " )
189
205
default :
You can’t perform that action at this time.
0 commit comments