ios AFNetworking下载超时怎么重试

FL丶凌风 2016-09-28 02:35:25
我拿到下载超时的回调,怎么让这个任务重新请求并且下载呢?
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];
...全文
547 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
FL丶凌风 2016-09-28
  • 打赏
  • 举报
回复
好吧已经解决了。。 我把下载封为一个方法,获取到超时信息后,得到超时的url,重新下载
if ([error.userInfo[@"NSLocalizedDescription"] isEqualToString:@"The request timed out."])
            {
                ZJLog(@"请求超时的url:%@", error.userInfo[@"NSErrorFailingURLKey"]);
                [self downloadTaskWithUrl:error.userInfo[@"NSErrorFailingURLKey"]];
                
            }

29,027

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧