33#import " TextResponseSerializer.h"
44#import " TextRequestSerializer.h"
55#import " AFHTTPSessionManager.h"
6+ #import " SDNetworkActivityIndicator.h"
67
78@interface CordovaHttpPlugin ()
89
@@ -172,6 +173,7 @@ - (void)post:(CDVInvokedUrlCommand*)command {
172173
173174 CordovaHttpPlugin* __weak weakSelf = self;
174175 manager.responseSerializer = [TextResponseSerializer serializer ];
176+ [[SDNetworkActivityIndicator sharedActivityIndicator ] startActivity ];
175177
176178 @try {
177179 [manager POST: url parameters: parameters progress: nil success: ^(NSURLSessionTask *task, id responseObject) {
@@ -180,15 +182,18 @@ - (void)post:(CDVInvokedUrlCommand*)command {
180182
181183 CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsDictionary: dictionary];
182184 [weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
185+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
183186 } failure: ^(NSURLSessionTask *task, NSError *error) {
184187 NSMutableDictionary *dictionary = [NSMutableDictionary dictionary ];
185188 [self handleError: dictionary withResponse: (NSHTTPURLResponse *)task.response error: error];
186189
187190 CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
188191 [weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
192+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
189193 }];
190194 }
191195 @catch (NSException *exception) {
196+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
192197 [self handleException: exception withCommand: command];
193198 }
194199}
@@ -210,6 +215,7 @@ - (void)get:(CDVInvokedUrlCommand*)command {
210215
211216 CordovaHttpPlugin* __weak weakSelf = self;
212217 manager.responseSerializer = [TextResponseSerializer serializer ];
218+ [[SDNetworkActivityIndicator sharedActivityIndicator ] startActivity ];
213219
214220 @try {
215221 [manager GET: url parameters: parameters progress: nil success: ^(NSURLSessionTask *task, id responseObject) {
@@ -218,15 +224,18 @@ - (void)get:(CDVInvokedUrlCommand*)command {
218224
219225 CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsDictionary: dictionary];
220226 [weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
227+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
221228 } failure: ^(NSURLSessionTask *task, NSError *error) {
222229 NSMutableDictionary *dictionary = [NSMutableDictionary dictionary ];
223230 [self handleError: dictionary withResponse: (NSHTTPURLResponse *)task.response error: error];
224231
225232 CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
226233 [weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
234+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
227235 }];
228236 }
229237 @catch (NSException *exception) {
238+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
230239 [self handleException: exception withCommand: command];
231240 }
232241}
@@ -248,6 +257,7 @@ - (void)put:(CDVInvokedUrlCommand*)command {
248257
249258 CordovaHttpPlugin* __weak weakSelf = self;
250259 manager.responseSerializer = [TextResponseSerializer serializer ];
260+ [[SDNetworkActivityIndicator sharedActivityIndicator ] startActivity ];
251261
252262 @try {
253263 [manager PUT: url parameters: parameters success: ^(NSURLSessionTask *task, id responseObject) {
@@ -256,15 +266,18 @@ - (void)put:(CDVInvokedUrlCommand*)command {
256266
257267 CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsDictionary: dictionary];
258268 [weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
269+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
259270 } failure: ^(NSURLSessionTask *task, NSError *error) {
260271 NSMutableDictionary *dictionary = [NSMutableDictionary dictionary ];
261272 [self handleError: dictionary withResponse: (NSHTTPURLResponse *)task.response error: error];
262273
263274 CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
264275 [weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
276+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
265277 }];
266278 }
267279 @catch (NSException *exception) {
280+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
268281 [self handleException: exception withCommand: command];
269282 }
270283}
@@ -286,6 +299,7 @@ - (void)patch:(CDVInvokedUrlCommand*)command {
286299
287300 CordovaHttpPlugin* __weak weakSelf = self;
288301 manager.responseSerializer = [TextResponseSerializer serializer ];
302+ [[SDNetworkActivityIndicator sharedActivityIndicator ] startActivity ];
289303
290304 @try {
291305 [manager PATCH: url parameters: parameters success: ^(NSURLSessionTask *task, id responseObject) {
@@ -294,15 +308,18 @@ - (void)patch:(CDVInvokedUrlCommand*)command {
294308
295309 CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsDictionary: dictionary];
296310 [weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
311+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
297312 } failure: ^(NSURLSessionTask *task, NSError *error) {
298313 NSMutableDictionary *dictionary = [NSMutableDictionary dictionary ];
299314 [self handleError: dictionary withResponse: (NSHTTPURLResponse *)task.response error: error];
300315
301316 CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
302317 [weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
318+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
303319 }];
304320 }
305321 @catch (NSException *exception) {
322+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
306323 [self handleException: exception withCommand: command];
307324 }
308325}
@@ -323,6 +340,7 @@ - (void)delete:(CDVInvokedUrlCommand*)command {
323340
324341 CordovaHttpPlugin* __weak weakSelf = self;
325342 manager.responseSerializer = [TextResponseSerializer serializer ];
343+ [[SDNetworkActivityIndicator sharedActivityIndicator ] startActivity ];
326344
327345 @try {
328346 [manager DELETE: url parameters: parameters success: ^(NSURLSessionTask *task, id responseObject) {
@@ -331,15 +349,18 @@ - (void)delete:(CDVInvokedUrlCommand*)command {
331349
332350 CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsDictionary: dictionary];
333351 [weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
352+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
334353 } failure: ^(NSURLSessionTask *task, NSError *error) {
335354 NSMutableDictionary *dictionary = [NSMutableDictionary dictionary ];
336355 [self handleError: dictionary withResponse: (NSHTTPURLResponse *)task.response error: error];
337356
338357 CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
339358 [weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
359+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
340360 }];
341361 }
342362 @catch (NSException *exception) {
363+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
343364 [self handleException: exception withCommand: command];
344365 }
345366}
@@ -358,6 +379,7 @@ - (void)head:(CDVInvokedUrlCommand*)command {
358379
359380 CordovaHttpPlugin* __weak weakSelf = self;
360381 manager.responseSerializer = [AFHTTPResponseSerializer serializer ];
382+ [[SDNetworkActivityIndicator sharedActivityIndicator ] startActivity ];
361383
362384 @try {
363385 [manager HEAD: url parameters: parameters success: ^(NSURLSessionTask *task) {
@@ -367,15 +389,18 @@ - (void)head:(CDVInvokedUrlCommand*)command {
367389
368390 CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsDictionary: dictionary];
369391 [weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
392+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
370393 } failure: ^(NSURLSessionTask *task, NSError *error) {
371394 NSMutableDictionary *dictionary = [NSMutableDictionary dictionary ];
372395 [self handleError: dictionary withResponse: (NSHTTPURLResponse *)task.response error: error];
373396
374397 CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
375398 [weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
399+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
376400 }];
377401 }
378402 @catch (NSException *exception) {
403+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
379404 [self handleException: exception withCommand: command];
380405 }
381406}
@@ -399,6 +424,7 @@ - (void)uploadFile:(CDVInvokedUrlCommand*)command {
399424
400425 CordovaHttpPlugin* __weak weakSelf = self;
401426 manager.responseSerializer = [TextResponseSerializer serializer ];
427+ [[SDNetworkActivityIndicator sharedActivityIndicator ] startActivity ];
402428
403429 @try {
404430 [manager POST: url parameters: parameters constructingBodyWithBlock: ^(id <AFMultipartFormData> formData) {
@@ -410,6 +436,7 @@ - (void)uploadFile:(CDVInvokedUrlCommand*)command {
410436 [dictionary setObject: @" Could not add file to post body." forKey: @" error" ];
411437 CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
412438 [weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
439+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
413440 return ;
414441 }
415442 } progress: nil success: ^(NSURLSessionTask *task, id responseObject) {
@@ -418,15 +445,18 @@ - (void)uploadFile:(CDVInvokedUrlCommand*)command {
418445
419446 CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsDictionary: dictionary];
420447 [weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
448+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
421449 } failure: ^(NSURLSessionTask *task, NSError *error) {
422450 NSMutableDictionary *dictionary = [NSMutableDictionary dictionary ];
423451 [self handleError: dictionary withResponse: (NSHTTPURLResponse *)task.response error: error];
424452
425453 CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
426454 [weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
455+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
427456 }];
428457 }
429458 @catch (NSException *exception) {
459+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
430460 [self handleException: exception withCommand: command];
431461 }
432462}
@@ -452,6 +482,7 @@ - (void)downloadFile:(CDVInvokedUrlCommand*)command {
452482
453483 CordovaHttpPlugin* __weak weakSelf = self;
454484 manager.responseSerializer = [AFHTTPResponseSerializer serializer ];
485+ [[SDNetworkActivityIndicator sharedActivityIndicator ] startActivity ];
455486
456487 @try {
457488 [manager GET: url parameters: parameters progress: nil success: ^(NSURLSessionTask *task, id responseObject) {
@@ -492,6 +523,7 @@ - (void)downloadFile:(CDVInvokedUrlCommand*)command {
492523 }
493524 CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
494525 [weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
526+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
495527 return ;
496528 }
497529 NSData *data = (NSData *)responseObject;
@@ -501,6 +533,7 @@ - (void)downloadFile:(CDVInvokedUrlCommand*)command {
501533 [dictionary setObject: @" Could not write the data to the given filePath." forKey: @" error" ];
502534 CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
503535 [weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
536+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
504537 return ;
505538 }
506539
@@ -511,16 +544,19 @@ - (void)downloadFile:(CDVInvokedUrlCommand*)command {
511544
512545 CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsDictionary: dictionary];
513546 [weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
547+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
514548 } failure: ^(NSURLSessionTask *task, NSError *error) {
515549 NSMutableDictionary *dictionary = [NSMutableDictionary dictionary ];
516550 [self handleError: dictionary withResponse: (NSHTTPURLResponse *)task.response error: error];
517551 [dictionary setObject: @" There was an error downloading the file" forKey: @" error" ];
518552
519553 CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsDictionary: dictionary];
520554 [weakSelf.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
555+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
521556 }];
522557 }
523558 @catch (NSException *exception) {
559+ [[SDNetworkActivityIndicator sharedActivityIndicator ] stopActivity ];
524560 [self handleException: exception withCommand: command];
525561 }
526562}
0 commit comments