@@ -32,8 +32,8 @@ @implementation RNFetchBlobNetwork
3232@synthesize callback;
3333@synthesize bridge;
3434@synthesize options;
35- @synthesize fileTaskCompletionHandler;
36- @synthesize dataTaskCompletionHandler;
35+ // @synthesize fileTaskCompletionHandler;
36+ // @synthesize dataTaskCompletionHandler;
3737@synthesize error;
3838
3939
@@ -88,7 +88,8 @@ - (void) sendRequest:(NSDictionary * _Nullable )options bridge:(RCTBridge * _Nu
8888 // file will be stored at a specific path
8989 if ( path != nil ) {
9090
91- self.fileTaskCompletionHandler = ^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
91+ // self.fileTaskCompletionHandler = ;
92+ NSURLSessionDownloadTask * task = [session downloadTaskWithRequest: req completionHandler: ^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
9293 if (error != nil ) {
9394 callback (@[[error localizedDescription ]]);
9495 return ;
@@ -102,14 +103,16 @@ - (void) sendRequest:(NSDictionary * _Nullable )options bridge:(RCTBridge * _Nu
102103 return ;
103104 }
104105 callback (@[[NSNull null ], path]);
105- };
106- NSURLSessionDownloadTask * task = [session downloadTaskWithRequest: req completionHandler: fileTaskCompletionHandler];
106+ // prevent memory leaks
107+ self.respData = nil ;
108+ }];
107109 [task resume ];
108110 }
109111 // file will be stored at tmp path
110112 else if ( [self .options valueForKey: CONFIG_USE_TEMP]!= nil ) {
111113
112- self.fileTaskCompletionHandler = ^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
114+ // self.fileTaskCompletionHandler;
115+ NSURLSessionDownloadTask * task = [session downloadTaskWithRequest: req completionHandler: ^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
113116 if (error != nil ) {
114117 callback (@[[error localizedDescription ]]);
115118 return ;
@@ -124,22 +127,23 @@ - (void) sendRequest:(NSDictionary * _Nullable )options bridge:(RCTBridge * _Nu
124127 return ;
125128 }
126129 callback (@[[NSNull null ], tmpPath]);
127- };
128- NSURLSessionDownloadTask * task = [session downloadTaskWithRequest: req completionHandler: fileTaskCompletionHandler];
130+ // prevent memory leaks
131+ self.respData = nil ;
132+ }];
129133 [task resume ];
130134 }
131135 // base64 response
132136 else {
133- self.dataTaskCompletionHandler = ^(NSData * _Nullable resp, NSURLResponse * _Nullable response, NSError * _Nullable error) {
137+ // self.dataTaskCompletionHandler = ;
138+ NSURLSessionDataTask * task = [session dataTaskWithRequest: req completionHandler: ^(NSData * _Nullable resp, NSURLResponse * _Nullable response, NSError * _Nullable error) {
134139 if (error != nil ) {
135140 callback (@[[error localizedDescription ]]);
136141 return ;
137142 }
138143 else {
139144 callback (@[[NSNull null ], [resp base64EncodedStringWithOptions: 0 ]]);
140145 }
141- };
142- NSURLSessionDataTask * task = [session dataTaskWithRequest: req completionHandler: dataTaskCompletionHandler];
146+ }];
143147 [task resume ];
144148 }
145149}
@@ -205,17 +209,17 @@ - (void) application:(UIApplication *)application handleEventsForBackgroundURLSe
205209
206210}
207211
208- - (void ) URLSessionDidFinishEventsForBackgroundURLSession : (NSURLSession *)session
209- {
210- if (self.dataTaskCompletionHandler != nil )
211- {
212- dataTaskCompletionHandler (self.respData , nil , error);
213- }
214- else if (self.fileTaskCompletionHandler != nil )
215- {
216- fileTaskCompletionHandler (nil , nil , self.error );
217- }
218- }
212+ // - (void) URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)session
213+ // {
214+ // if(self.dataTaskCompletionHandler != nil)
215+ // {
216+ // dataTaskCompletionHandler(self.respData, nil, error);
217+ // }
218+ // else if(self.fileTaskCompletionHandler != nil)
219+ // {
220+ // fileTaskCompletionHandler(nil, nil, self.error);
221+ // }
222+ // }
219223
220224- (void ) URLSession : (NSURLSession *)session task : (NSURLSessionTask *)task didReceiveChallenge : (NSURLAuthenticationChallenge *)challenge completionHandler : (void (^)(NSURLSessionAuthChallengeDisposition , NSURLCredential * _Nullable))completionHandler
221225{
0 commit comments