我拿到下载超时的回调,怎么让这个任务重新请求并且下载呢?
NSURLSessionDownloadTask *downloadTask =  [self.sessionManager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
            
            return [NSURL fileURLWithPath:RellayPath(_userInfor.UserID)];
            
        } completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error)
         {
             if (![error.userInfo[@"NSLocalizedDescription"] isEqualToString:@"cancelled"])
             {
                 ZJLog(@"%@", error.userInfo[@"NSLocalizedDescription"]);
                 
                 if (![error.userInfo[@"NSLocalizedDescription"] isEqualToString:@"The request timed out."])
                 {
                     
                 }
                 count++;
                 
                 float progress = (float)(count) / downCount * 100;
                 
                 ZJLog(@"%f", progress);
                 
                 if (progress < 99)
                 {
                     self.downProgressLabel.text = [NSString stringWithFormat:@"%2.0f%%", progress];
                 }
                 else
                 {
                     self.downProgressLabel.text = @"99%";
                 }
                 
                 
                 if (count == downCount)
                 {
                     self.downProgressLabel.text = @"100%";
                     [self changeStatus:Completion];
                 }
             }
             
         }];
        [downloadTask resume];

解决方案 »

  1.   

    好吧已经解决了。。
    我把下载封为一个方法,获取到超时信息后,得到超时的url,重新下载
    if ([error.userInfo[@"NSLocalizedDescription"] isEqualToString:@"The request timed out."])
                {
                    ZJLog(@"请求超时的url:%@", error.userInfo[@"NSErrorFailingURLKey"]);
                    [self downloadTaskWithUrl:error.userInfo[@"NSErrorFailingURLKey"]];
                    
                }