Skip to content

Commit 3d18254

Browse files
fix delegate sometimes not release
1 parent 3661110 commit 3d18254

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

QiniuSDK/Http/QNSessionManager.m

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,6 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
5858
if (_cancelBlock && _cancelBlock()) {
5959
[_task cancel];
6060
}
61-
62-
float progress = (float)totalBytesSent / totalBytesExpectedToSend;
63-
if (progress == 1.0f) {
64-
self.task = nil;
65-
self.cancelBlock = nil;
66-
self.progressBlock = nil;
67-
}
6861
}
6962

7063
@end
@@ -203,7 +196,7 @@ - (void)sendRequest2:(NSMutableURLRequest *)request
203196
QNInternalProgressBlock progressBlock2 = ^(long long totalBytesWritten, long long totalBytesExpectedToWrite) {
204197
progressBlock(totalBytesWritten, totalBytesExpectedToWrite);
205198
};
206-
QNProgessDelegate *delegate = (QNProgessDelegate *)_httpManager.delegate;
199+
__block QNProgessDelegate *delegate = (QNProgessDelegate *)_httpManager.delegate;
207200
delegate.progressBlock = progressBlock2;
208201
NSURLSessionUploadTask *uploadTask = [_httpManager uploadTaskWithRequest:request fromData:nil completionHandler:^(NSData *_Nullable data, NSURLResponse *_Nullable response, NSError *_Nullable error) {
209202

@@ -224,6 +217,9 @@ - (void)sendRequest2:(NSMutableURLRequest *)request
224217
} else {
225218
info = [QNSessionManager buildResponseInfo:httpResponse withError:error withDuration:duration withResponse:data withHost:domain withIp:ip];
226219
}
220+
delegate.task = nil;
221+
delegate.cancelBlock = nil;
222+
delegate.progressBlock = nil;
227223
completeBlock(info, resp);
228224
}];
229225
delegate.task = uploadTask;

QiniuSDKTests/QNFileRecorderTest.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ - (void) template:(int)size pos:(float)pos {
8282
if (percent < pos - 256.0 / size) {
8383
failed = YES;
8484
}
85-
NSLog(@"continue progress %f", percent);
85+
NSLog(@"continue progress %f,%f", percent,pos - 256.0 / size);
8686
}
8787
params:nil
8888
checkCrc:NO
@@ -92,6 +92,7 @@ - (void) template:(int)size pos:(float)pos {
9292
info = i;
9393
}
9494
option:opt];
95+
NSLog(@"failed: %@",failed ? @"YES" : @"NO");
9596
AGWW_WAIT_WHILE(key == nil, 60 * 30);
9697
NSLog(@"info %@", info);
9798
XCTAssert(info.isOK, @"Pass");
@@ -132,7 +133,7 @@ - (void)test8M {
132133
if (_inTravis) {
133134
return;
134135
}
135-
[self template:8 * 1024 + 1 pos:0.8];
136+
[self template:8 * 1024 + 1 pos:0.7];
136137
}
137138

138139
//#endif

0 commit comments

Comments
 (0)