3
3
#import " TextResponseSerializer.h"
4
4
#import " TextRequestSerializer.h"
5
5
#import " AFHTTPSessionManager.h"
6
+ #import " SDNetworkActivityIndicator.h"
6
7
7
8
@interface CordovaHttpPlugin ()
8
9
@@ -172,6 +173,7 @@ - (void)post:(CDVInvokedUrlCommand*)command {
172
173
173
174
CordovaHttpPlugin* __weak weakSelf = self;
174
175
manager.responseSerializer = [TextResponseSerializer serializer ];
176
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] startActivity ];
175
177
176
178
@try {
177
179
[manager POST: url parameters: parameters progress: nil success: ^(NSURLSessionTask *task, id responseObject) {
@@ -180,15 +182,18 @@ - (void)post:(CDVInvokedUrlCommand*)command {
180
182
181
183
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsDictionary: dictionary];
182
184
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
185
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
183
186
} failure: ^(NSURLSessionTask *task, NSError *error) {
184
187
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary ];
185
188
[self handleError: dictionary withResponse: (NSHTTPURLResponse *)task.response error: error];
186
189
187
190
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
188
191
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
192
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
189
193
}];
190
194
}
191
195
@catch (NSException *exception) {
196
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
192
197
[self handleException: exception withCommand: command];
193
198
}
194
199
}
@@ -210,6 +215,7 @@ - (void)get:(CDVInvokedUrlCommand*)command {
210
215
211
216
CordovaHttpPlugin* __weak weakSelf = self;
212
217
manager.responseSerializer = [TextResponseSerializer serializer ];
218
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] startActivity ];
213
219
214
220
@try {
215
221
[manager GET: url parameters: parameters progress: nil success: ^(NSURLSessionTask *task, id responseObject) {
@@ -218,15 +224,18 @@ - (void)get:(CDVInvokedUrlCommand*)command {
218
224
219
225
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsDictionary: dictionary];
220
226
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
227
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
221
228
} failure: ^(NSURLSessionTask *task, NSError *error) {
222
229
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary ];
223
230
[self handleError: dictionary withResponse: (NSHTTPURLResponse *)task.response error: error];
224
231
225
232
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
226
233
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
234
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
227
235
}];
228
236
}
229
237
@catch (NSException *exception) {
238
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
230
239
[self handleException: exception withCommand: command];
231
240
}
232
241
}
@@ -248,6 +257,7 @@ - (void)put:(CDVInvokedUrlCommand*)command {
248
257
249
258
CordovaHttpPlugin* __weak weakSelf = self;
250
259
manager.responseSerializer = [TextResponseSerializer serializer ];
260
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] startActivity ];
251
261
252
262
@try {
253
263
[manager PUT: url parameters: parameters success: ^(NSURLSessionTask *task, id responseObject) {
@@ -256,15 +266,18 @@ - (void)put:(CDVInvokedUrlCommand*)command {
256
266
257
267
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsDictionary: dictionary];
258
268
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
269
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
259
270
} failure: ^(NSURLSessionTask *task, NSError *error) {
260
271
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary ];
261
272
[self handleError: dictionary withResponse: (NSHTTPURLResponse *)task.response error: error];
262
273
263
274
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
264
275
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
276
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
265
277
}];
266
278
}
267
279
@catch (NSException *exception) {
280
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
268
281
[self handleException: exception withCommand: command];
269
282
}
270
283
}
@@ -286,6 +299,7 @@ - (void)patch:(CDVInvokedUrlCommand*)command {
286
299
287
300
CordovaHttpPlugin* __weak weakSelf = self;
288
301
manager.responseSerializer = [TextResponseSerializer serializer ];
302
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] startActivity ];
289
303
290
304
@try {
291
305
[manager PATCH: url parameters: parameters success: ^(NSURLSessionTask *task, id responseObject) {
@@ -294,15 +308,18 @@ - (void)patch:(CDVInvokedUrlCommand*)command {
294
308
295
309
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsDictionary: dictionary];
296
310
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
311
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
297
312
} failure: ^(NSURLSessionTask *task, NSError *error) {
298
313
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary ];
299
314
[self handleError: dictionary withResponse: (NSHTTPURLResponse *)task.response error: error];
300
315
301
316
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
302
317
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
318
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
303
319
}];
304
320
}
305
321
@catch (NSException *exception) {
322
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
306
323
[self handleException: exception withCommand: command];
307
324
}
308
325
}
@@ -323,6 +340,7 @@ - (void)delete:(CDVInvokedUrlCommand*)command {
323
340
324
341
CordovaHttpPlugin* __weak weakSelf = self;
325
342
manager.responseSerializer = [TextResponseSerializer serializer ];
343
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] startActivity ];
326
344
327
345
@try {
328
346
[manager DELETE: url parameters: parameters success: ^(NSURLSessionTask *task, id responseObject) {
@@ -331,15 +349,18 @@ - (void)delete:(CDVInvokedUrlCommand*)command {
331
349
332
350
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsDictionary: dictionary];
333
351
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
352
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
334
353
} failure: ^(NSURLSessionTask *task, NSError *error) {
335
354
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary ];
336
355
[self handleError: dictionary withResponse: (NSHTTPURLResponse *)task.response error: error];
337
356
338
357
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
339
358
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
359
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
340
360
}];
341
361
}
342
362
@catch (NSException *exception) {
363
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
343
364
[self handleException: exception withCommand: command];
344
365
}
345
366
}
@@ -358,6 +379,7 @@ - (void)head:(CDVInvokedUrlCommand*)command {
358
379
359
380
CordovaHttpPlugin* __weak weakSelf = self;
360
381
manager.responseSerializer = [AFHTTPResponseSerializer serializer ];
382
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] startActivity ];
361
383
362
384
@try {
363
385
[manager HEAD: url parameters: parameters success: ^(NSURLSessionTask *task) {
@@ -367,15 +389,18 @@ - (void)head:(CDVInvokedUrlCommand*)command {
367
389
368
390
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsDictionary: dictionary];
369
391
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
392
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
370
393
} failure: ^(NSURLSessionTask *task, NSError *error) {
371
394
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary ];
372
395
[self handleError: dictionary withResponse: (NSHTTPURLResponse *)task.response error: error];
373
396
374
397
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
375
398
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
399
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
376
400
}];
377
401
}
378
402
@catch (NSException *exception) {
403
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
379
404
[self handleException: exception withCommand: command];
380
405
}
381
406
}
@@ -399,6 +424,7 @@ - (void)uploadFile:(CDVInvokedUrlCommand*)command {
399
424
400
425
CordovaHttpPlugin* __weak weakSelf = self;
401
426
manager.responseSerializer = [TextResponseSerializer serializer ];
427
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] startActivity ];
402
428
403
429
@try {
404
430
[manager POST: url parameters: parameters constructingBodyWithBlock: ^(id <AFMultipartFormData> formData) {
@@ -410,6 +436,7 @@ - (void)uploadFile:(CDVInvokedUrlCommand*)command {
410
436
[dictionary setObject: @" Could not add file to post body." forKey: @" error" ];
411
437
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
412
438
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
439
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
413
440
return ;
414
441
}
415
442
} progress: nil success: ^(NSURLSessionTask *task, id responseObject) {
@@ -418,15 +445,18 @@ - (void)uploadFile:(CDVInvokedUrlCommand*)command {
418
445
419
446
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsDictionary: dictionary];
420
447
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
448
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
421
449
} failure: ^(NSURLSessionTask *task, NSError *error) {
422
450
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary ];
423
451
[self handleError: dictionary withResponse: (NSHTTPURLResponse *)task.response error: error];
424
452
425
453
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
426
454
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
455
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
427
456
}];
428
457
}
429
458
@catch (NSException *exception) {
459
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
430
460
[self handleException: exception withCommand: command];
431
461
}
432
462
}
@@ -452,6 +482,7 @@ - (void)downloadFile:(CDVInvokedUrlCommand*)command {
452
482
453
483
CordovaHttpPlugin* __weak weakSelf = self;
454
484
manager.responseSerializer = [AFHTTPResponseSerializer serializer ];
485
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] startActivity ];
455
486
456
487
@try {
457
488
[manager GET: url parameters: parameters progress: nil success: ^(NSURLSessionTask *task, id responseObject) {
@@ -492,6 +523,7 @@ - (void)downloadFile:(CDVInvokedUrlCommand*)command {
492
523
}
493
524
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
494
525
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
526
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
495
527
return ;
496
528
}
497
529
NSData *data = (NSData *)responseObject;
@@ -501,6 +533,7 @@ - (void)downloadFile:(CDVInvokedUrlCommand*)command {
501
533
[dictionary setObject: @" Could not write the data to the given filePath." forKey: @" error" ];
502
534
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
503
535
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
536
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
504
537
return ;
505
538
}
506
539
@@ -511,16 +544,19 @@ - (void)downloadFile:(CDVInvokedUrlCommand*)command {
511
544
512
545
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsDictionary: dictionary];
513
546
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
547
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
514
548
} failure: ^(NSURLSessionTask *task, NSError *error) {
515
549
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary ];
516
550
[self handleError: dictionary withResponse: (NSHTTPURLResponse *)task.response error: error];
517
551
[dictionary setObject: @" There was an error downloading the file" forKey: @" error" ];
518
552
519
553
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
520
554
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
555
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
521
556
}];
522
557
}
523
558
@catch (NSException *exception) {
559
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
524
560
[self handleException: exception withCommand: command];
525
561
}
526
562
}
0 commit comments