@@ -32,8 +32,8 @@ @implementation RNFetchBlobNetwork
32
32
@synthesize callback;
33
33
@synthesize bridge;
34
34
@synthesize options;
35
- @synthesize fileTaskCompletionHandler;
36
- @synthesize dataTaskCompletionHandler;
35
+ // @synthesize fileTaskCompletionHandler;
36
+ // @synthesize dataTaskCompletionHandler;
37
37
@synthesize error;
38
38
39
39
@@ -88,7 +88,8 @@ - (void) sendRequest:(NSDictionary * _Nullable )options bridge:(RCTBridge * _Nu
88
88
// file will be stored at a specific path
89
89
if ( path != nil ) {
90
90
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) {
92
93
if (error != nil ) {
93
94
callback (@[[error localizedDescription ]]);
94
95
return ;
@@ -102,14 +103,16 @@ - (void) sendRequest:(NSDictionary * _Nullable )options bridge:(RCTBridge * _Nu
102
103
return ;
103
104
}
104
105
callback (@[[NSNull null ], path]);
105
- };
106
- NSURLSessionDownloadTask * task = [session downloadTaskWithRequest: req completionHandler: fileTaskCompletionHandler];
106
+ // prevent memory leaks
107
+ self.respData = nil ;
108
+ }];
107
109
[task resume ];
108
110
}
109
111
// file will be stored at tmp path
110
112
else if ( [self .options valueForKey: CONFIG_USE_TEMP]!= nil ) {
111
113
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) {
113
116
if (error != nil ) {
114
117
callback (@[[error localizedDescription ]]);
115
118
return ;
@@ -124,22 +127,23 @@ - (void) sendRequest:(NSDictionary * _Nullable )options bridge:(RCTBridge * _Nu
124
127
return ;
125
128
}
126
129
callback (@[[NSNull null ], tmpPath]);
127
- };
128
- NSURLSessionDownloadTask * task = [session downloadTaskWithRequest: req completionHandler: fileTaskCompletionHandler];
130
+ // prevent memory leaks
131
+ self.respData = nil ;
132
+ }];
129
133
[task resume ];
130
134
}
131
135
// base64 response
132
136
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) {
134
139
if (error != nil ) {
135
140
callback (@[[error localizedDescription ]]);
136
141
return ;
137
142
}
138
143
else {
139
144
callback (@[[NSNull null ], [resp base64EncodedStringWithOptions: 0 ]]);
140
145
}
141
- };
142
- NSURLSessionDataTask * task = [session dataTaskWithRequest: req completionHandler: dataTaskCompletionHandler];
146
+ }];
143
147
[task resume ];
144
148
}
145
149
}
@@ -205,17 +209,17 @@ - (void) application:(UIApplication *)application handleEventsForBackgroundURLSe
205
209
206
210
}
207
211
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
+ // }
219
223
220
224
- (void ) URLSession : (NSURLSession *)session task : (NSURLSessionTask *)task didReceiveChallenge : (NSURLAuthenticationChallenge *)challenge completionHandler : (void (^)(NSURLSessionAuthChallengeDisposition , NSURLCredential * _Nullable))completionHandler
221
225
{
0 commit comments