From af9a4a4df72fe6238ddffeb8c72711ac34b6d584 Mon Sep 17 00:00:00 2001 From: "Juan B. Rodriguez" Date: Mon, 8 Aug 2016 14:24:27 -0500 Subject: [PATCH] Fix callback signature The callback from Java/iOS now returns 3 arguments. A small adjustment is needed to fix this, with regards to the cache feature. --- .../java/com/RNFetchBlob/RNFetchBlobReq.java | 2 +- src/ios/RNFetchBlobNetwork.m | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java b/src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java index 363a0aa33..1bf115020 100644 --- a/src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java +++ b/src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java @@ -165,7 +165,7 @@ public void run() { File file = new File(RNFetchBlobFS.getTmpPath(RNFetchBlob.RCTContext, cacheKey) + ext); if (file.exists()) { - callback.invoke(null, file.getAbsolutePath()); + callback.invoke(null, null, file.getAbsolutePath()); return; } } diff --git a/src/ios/RNFetchBlobNetwork.m b/src/ios/RNFetchBlobNetwork.m index 25a48d2db..7311ae03a 100644 --- a/src/ios/RNFetchBlobNetwork.m +++ b/src/ios/RNFetchBlobNetwork.m @@ -133,7 +133,7 @@ - (void) sendRequest:(__weak NSDictionary * _Nullable )options // the session trust any SSL certification - + NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration]; if([options valueForKey:@"timeout"] != nil) { @@ -153,7 +153,7 @@ - (void) sendRequest:(__weak NSDictionary * _Nullable )options destPath = [RNFetchBlobFS getTempPath:cacheKey withExtension:[self.options valueForKey:CONFIG_FILE_EXT]]; if ([[NSFileManager defaultManager] fileExistsAtPath:destPath]) { - callback(@[[NSNull null], destPath]); + callback(@[[NSNull null], @[[NSNull null], destPath]); return; } } @@ -190,7 +190,7 @@ - (void) sendRequest:(__weak NSDictionary * _Nullable )options - (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)response completionHandler:(void (^)(NSURLSessionResponseDisposition))completionHandler { expectedBytes = [response expectedContentLength]; - + NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response; NSInteger statusCode = [(NSHTTPURLResponse *)response statusCode]; if ([response respondsToSelector:@selector(allHeaderFields)]) @@ -229,7 +229,7 @@ - (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dat @"timeout" : @NO, @"status": [NSString stringWithFormat:@"%d", statusCode ] }; - + [self.bridge.eventDispatcher sendDeviceEventWithName: EVENT_STATE_CHANGE body:respInfo @@ -272,7 +272,7 @@ - (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dat { [writeStream write:[data bytes] maxLength:[data length]]; } - + if([progressTable valueForKey:taskId] == @YES) { [self.bridge.eventDispatcher @@ -296,15 +296,15 @@ - (void) URLSession:(NSURLSession *)session didBecomeInvalidWithError:(nullable - (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error { - + self.error = error; [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; - + NSString * respType = [respInfo valueForKey:@"respType"]; if(error != nil) { NSLog([error localizedDescription]); } - + if(respFile == YES) { [writeStream close]; @@ -321,7 +321,7 @@ - (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCom [respData base64EncodedStringWithOptions:0] ]); } - + [taskTable removeObjectForKey:taskId]; [uploadProgressTable removeObjectForKey:taskId]; [progressTable removeObjectForKey:taskId];