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
@@ -175,6 +176,7 @@ - (void)post:(CDVInvokedUrlCommand*)command {
175
176
176
177
CordovaHttpPlugin* __weak weakSelf = self;
177
178
manager.responseSerializer = [TextResponseSerializer serializer ];
179
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] startActivity ];
178
180
179
181
@try {
180
182
[manager POST: url parameters: parameters progress: nil success: ^(NSURLSessionTask *task, id responseObject) {
@@ -183,15 +185,18 @@ - (void)post:(CDVInvokedUrlCommand*)command {
183
185
184
186
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsDictionary: dictionary];
185
187
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
188
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
186
189
} failure: ^(NSURLSessionTask *task, NSError *error) {
187
190
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary ];
188
191
[self handleError: dictionary withResponse: (NSHTTPURLResponse *)task.response error: error];
189
192
190
193
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
191
194
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
195
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
192
196
}];
193
197
}
194
198
@catch (NSException *exception) {
199
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
195
200
[self handleException: exception withCommand: command];
196
201
}
197
202
}
@@ -213,6 +218,7 @@ - (void)get:(CDVInvokedUrlCommand*)command {
213
218
214
219
CordovaHttpPlugin* __weak weakSelf = self;
215
220
manager.responseSerializer = [TextResponseSerializer serializer ];
221
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] startActivity ];
216
222
217
223
@try {
218
224
[manager GET: url parameters: parameters progress: nil success: ^(NSURLSessionTask *task, id responseObject) {
@@ -221,15 +227,18 @@ - (void)get:(CDVInvokedUrlCommand*)command {
221
227
222
228
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsDictionary: dictionary];
223
229
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
230
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
224
231
} failure: ^(NSURLSessionTask *task, NSError *error) {
225
232
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary ];
226
233
[self handleError: dictionary withResponse: (NSHTTPURLResponse *)task.response error: error];
227
234
228
235
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
229
236
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
237
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
230
238
}];
231
239
}
232
240
@catch (NSException *exception) {
241
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
233
242
[self handleException: exception withCommand: command];
234
243
}
235
244
}
@@ -251,6 +260,7 @@ - (void)put:(CDVInvokedUrlCommand*)command {
251
260
252
261
CordovaHttpPlugin* __weak weakSelf = self;
253
262
manager.responseSerializer = [TextResponseSerializer serializer ];
263
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] startActivity ];
254
264
255
265
@try {
256
266
[manager PUT: url parameters: parameters success: ^(NSURLSessionTask *task, id responseObject) {
@@ -259,15 +269,18 @@ - (void)put:(CDVInvokedUrlCommand*)command {
259
269
260
270
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsDictionary: dictionary];
261
271
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
272
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
262
273
} failure: ^(NSURLSessionTask *task, NSError *error) {
263
274
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary ];
264
275
[self handleError: dictionary withResponse: (NSHTTPURLResponse *)task.response error: error];
265
276
266
277
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
267
278
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
279
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
268
280
}];
269
281
}
270
282
@catch (NSException *exception) {
283
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
271
284
[self handleException: exception withCommand: command];
272
285
}
273
286
}
@@ -289,6 +302,7 @@ - (void)patch:(CDVInvokedUrlCommand*)command {
289
302
290
303
CordovaHttpPlugin* __weak weakSelf = self;
291
304
manager.responseSerializer = [TextResponseSerializer serializer ];
305
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] startActivity ];
292
306
293
307
@try {
294
308
[manager PATCH: url parameters: parameters success: ^(NSURLSessionTask *task, id responseObject) {
@@ -297,15 +311,18 @@ - (void)patch:(CDVInvokedUrlCommand*)command {
297
311
298
312
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsDictionary: dictionary];
299
313
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
314
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
300
315
} failure: ^(NSURLSessionTask *task, NSError *error) {
301
316
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary ];
302
317
[self handleError: dictionary withResponse: (NSHTTPURLResponse *)task.response error: error];
303
318
304
319
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
305
320
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
321
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
306
322
}];
307
323
}
308
324
@catch (NSException *exception) {
325
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
309
326
[self handleException: exception withCommand: command];
310
327
}
311
328
}
@@ -326,6 +343,7 @@ - (void)delete:(CDVInvokedUrlCommand*)command {
326
343
327
344
CordovaHttpPlugin* __weak weakSelf = self;
328
345
manager.responseSerializer = [TextResponseSerializer serializer ];
346
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] startActivity ];
329
347
330
348
@try {
331
349
[manager DELETE: url parameters: parameters success: ^(NSURLSessionTask *task, id responseObject) {
@@ -334,15 +352,18 @@ - (void)delete:(CDVInvokedUrlCommand*)command {
334
352
335
353
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsDictionary: dictionary];
336
354
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
355
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
337
356
} failure: ^(NSURLSessionTask *task, NSError *error) {
338
357
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary ];
339
358
[self handleError: dictionary withResponse: (NSHTTPURLResponse *)task.response error: error];
340
359
341
360
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
342
361
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
362
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
343
363
}];
344
364
}
345
365
@catch (NSException *exception) {
366
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
346
367
[self handleException: exception withCommand: command];
347
368
}
348
369
}
@@ -361,6 +382,7 @@ - (void)head:(CDVInvokedUrlCommand*)command {
361
382
362
383
CordovaHttpPlugin* __weak weakSelf = self;
363
384
manager.responseSerializer = [AFHTTPResponseSerializer serializer ];
385
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] startActivity ];
364
386
365
387
@try {
366
388
[manager HEAD: url parameters: parameters success: ^(NSURLSessionTask *task) {
@@ -370,15 +392,18 @@ - (void)head:(CDVInvokedUrlCommand*)command {
370
392
371
393
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsDictionary: dictionary];
372
394
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
395
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
373
396
} failure: ^(NSURLSessionTask *task, NSError *error) {
374
397
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary ];
375
398
[self handleError: dictionary withResponse: (NSHTTPURLResponse *)task.response error: error];
376
399
377
400
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
378
401
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
402
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
379
403
}];
380
404
}
381
405
@catch (NSException *exception) {
406
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
382
407
[self handleException: exception withCommand: command];
383
408
}
384
409
}
@@ -402,6 +427,7 @@ - (void)uploadFile:(CDVInvokedUrlCommand*)command {
402
427
403
428
CordovaHttpPlugin* __weak weakSelf = self;
404
429
manager.responseSerializer = [TextResponseSerializer serializer ];
430
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] startActivity ];
405
431
406
432
@try {
407
433
[manager POST: url parameters: parameters constructingBodyWithBlock: ^(id <AFMultipartFormData> formData) {
@@ -413,6 +439,7 @@ - (void)uploadFile:(CDVInvokedUrlCommand*)command {
413
439
[dictionary setObject: @" Could not add file to post body." forKey: @" error" ];
414
440
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
415
441
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
442
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
416
443
return ;
417
444
}
418
445
} progress: nil success: ^(NSURLSessionTask *task, id responseObject) {
@@ -421,15 +448,18 @@ - (void)uploadFile:(CDVInvokedUrlCommand*)command {
421
448
422
449
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsDictionary: dictionary];
423
450
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
451
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
424
452
} failure: ^(NSURLSessionTask *task, NSError *error) {
425
453
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary ];
426
454
[self handleError: dictionary withResponse: (NSHTTPURLResponse *)task.response error: error];
427
455
428
456
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
429
457
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
458
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
430
459
}];
431
460
}
432
461
@catch (NSException *exception) {
462
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
433
463
[self handleException: exception withCommand: command];
434
464
}
435
465
}
@@ -455,6 +485,7 @@ - (void)downloadFile:(CDVInvokedUrlCommand*)command {
455
485
456
486
CordovaHttpPlugin* __weak weakSelf = self;
457
487
manager.responseSerializer = [AFHTTPResponseSerializer serializer ];
488
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] startActivity ];
458
489
459
490
@try {
460
491
[manager GET: url parameters: parameters progress: nil success: ^(NSURLSessionTask *task, id responseObject) {
@@ -495,6 +526,7 @@ - (void)downloadFile:(CDVInvokedUrlCommand*)command {
495
526
}
496
527
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
497
528
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
529
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
498
530
return ;
499
531
}
500
532
NSData *data = (NSData *)responseObject;
@@ -504,6 +536,7 @@ - (void)downloadFile:(CDVInvokedUrlCommand*)command {
504
536
[dictionary setObject: @" Could not write the data to the given filePath." forKey: @" error" ];
505
537
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
506
538
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
539
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
507
540
return ;
508
541
}
509
542
@@ -514,16 +547,19 @@ - (void)downloadFile:(CDVInvokedUrlCommand*)command {
514
547
515
548
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsDictionary: dictionary];
516
549
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
550
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
517
551
} failure: ^(NSURLSessionTask *task, NSError *error) {
518
552
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary ];
519
553
[self handleError: dictionary withResponse: (NSHTTPURLResponse *)task.response error: error];
520
554
[dictionary setObject: @" There was an error downloading the file" forKey: @" error" ];
521
555
522
556
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
523
557
[weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
558
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
524
559
}];
525
560
}
526
561
@catch (NSException *exception) {
562
+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
527
563
[self handleException: exception withCommand: command];
528
564
}
529
565
}
0 commit comments