File tree 1 file changed +11
-7
lines changed
1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -236,11 +236,15 @@ - (void)didReceiveResponse:(NSHTTPURLResponse *)response
236
236
- (void )didReceiveData : (NSData *)data
237
237
{
238
238
// 写数据
239
- [self .stream write :data.bytes maxLength: data.length];
240
- self.bytesWritten = data.length ;
241
-
242
- // 通知进度改变
243
- [self notifyProgressChange ];
239
+ NSInteger result = [self .stream write :data.bytes maxLength: data.length];
240
+
241
+ if (result == -1 ) {
242
+ self.error = self.stream .streamError ;
243
+ [self .task cancel ]; // 取消请求
244
+ }else {
245
+ self.bytesWritten = data.length ;
246
+ [self notifyProgressChange ]; // 通知进度改变
247
+ }
244
248
}
245
249
246
250
- (void )didCompleteWithError : (NSError *)error
@@ -251,8 +255,8 @@ - (void)didCompleteWithError:(NSError *)error
251
255
self.stream = nil ;
252
256
self.task = nil ;
253
257
254
- // 错误
255
- self.error = error;
258
+ // 错误(避免nil的error覆盖掉之前设置的self.error)
259
+ self.error = error ? error : self. error ;
256
260
257
261
// 通知(如果下载完毕 或者 下载出错了)
258
262
if (self.state == MJDownloadStateCompleted || error) {
You can’t perform that action at this time.
0 commit comments