diff --git a/AFHTTPRequestOperationManager+AutoRetry.h b/AFHTTPRequestOperationManager+AutoRetry.h index 7d2f87c..3a304ad 100644 --- a/AFHTTPRequestOperationManager+AutoRetry.h +++ b/AFHTTPRequestOperationManager+AutoRetry.h @@ -7,11 +7,13 @@ #pragma clang diagnostic push #pragma ide diagnostic ignored "OCUnusedMethodInspection" +#define INCREASE_TIMEOUT_RATIO 1.5 + typedef int (^RetryDelayCalcBlock)(int, int, int); // int totalRetriesAllowed, int retriesRemaining, int delayBetweenIntervalsModifier @interface AFHTTPRequestOperationManager (AutoRetry) -- (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)request +- (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSMutableURLRequest *)request success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure autoRetryOf:(int)retriesRemaining @@ -115,4 +117,4 @@ typedef int (^RetryDelayCalcBlock)(int, int, int); // int totalRetriesAllowed, i @end -#pragma clang diagnostic pop \ No newline at end of file +#pragma clang diagnostic pop diff --git a/AFHTTPRequestOperationManager+AutoRetry.m b/AFHTTPRequestOperationManager+AutoRetry.m index a0c96ad..4366c92 100644 --- a/AFHTTPRequestOperationManager+AutoRetry.m +++ b/AFHTTPRequestOperationManager+AutoRetry.m @@ -38,7 +38,7 @@ - (id)operationsDict { return self.__operationsDict; } -- (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)request +- (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSMutableURLRequest *)request success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure autoRetryOf:(int)retriesRemaining retryInterval:(int)intervalInSeconds { @@ -59,6 +59,14 @@ - (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)requ [self.operationQueue addOperation:retryOperation]; }; RetryDelayCalcBlock delayCalc = self.retryDelayCalcBlock; + + if ([request isKindOfClass:[NSMutableURLRequest class]]) { + request.timeoutInterval=request.timeoutInterval*INCREASE_TIMEOUT_RATIO; + NSLog(@"AutoRetry: increasing time to %f seconds...", request.timeoutInterval); + } else { + NSLog(@"AutoRetry: not increasing timeout"); + } + int intervalToWait = delayCalc(originalRetryCount, retriesRemainingCount, intervalInSeconds); if (intervalToWait > 0) { NSLog(@"AutoRetry: Delaying retry for %d seconds...", intervalToWait); @@ -70,7 +78,7 @@ - (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)requ addRetryOperation(); } } else { - NSLog(@"AutoRetry: Request failed %d times: %@", originalRetryCount, error.localizedDescription); + NSLog(@"AutoRetry: Request %@ failed %d times: %@",request, originalRetryCount, error.localizedDescription); NSLog(@"AutoRetry: No more retries allowed! executing supplied failure block..."); failure(operation, error); NSLog(@"AutoRetry: done."); @@ -227,4 +235,4 @@ - (AFHTTPRequestOperation *)DELETE:(NSString *)URLString @end -#pragma clang diagnostic pop \ No newline at end of file +#pragma clang diagnostic pop