iOS·下载管理第三方框架初步调研

笔者目前比较关注的点是第三方框架中,删除指定下载任务的处理逻辑。

1.FGDownloader

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    TaskModel *model=[_dataArray objectAtIndex:indexPath.row];
    [[FGDownloadManager shredManager] removeForUrl:model.url file:model.destinationPath];
    [_dataArray removeObjectAtIndex:indexPath.row];
    [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    __weak typeof(self) wkself=self;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        dispatch_async(dispatch_get_main_queue(), ^{
            [wkself.tbView reloadData];
        });
    });
}
  • 问题
    移除的方法里边有bug 当其他任务在下载的时候 移除会导致无法暂停
    [[FGGDownloadManager shredManager] removeForUrl:model.url file:model.destinationPath];移除的时候下载队列出问题了

  • 问题地址
    https://github.com/Insfgg99x/FGDownloader/issues/4

2.HJDownloadManager

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
   __weak HJDownloadListCell *weakCell = [tableView cellForRowAtIndexPath:indexPath];
    __weak typeof(self) weakSelf = self;
    
    UITableViewRowAction *action = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
        [tableView beginUpdates];
        
        HJDownloadModel *downloadModel = weakCell.downloadModel;
        [kHJDownloadManager stopWithDownloadModel:weakSelf.datas[indexPath.row]];
        [weakSelf.datas removeObject:downloadModel];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationBottom];
       
        [tableView endUpdates];
    }];
    
  • 问题
    下载进度的回调可能有BUG:可能是这个回调不准_downloadModel.progressChanged。表现为:直到下载成功才直到下载了,下载中无法知道是否下载状态。

3.TCBlobDownload

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        TCBlobDownloader *download = self.currentDownloads[indexPath.row];
        [download cancelDownloadAndRemoveFile:YES];
        
        NSInteger index = [self.currentDownloads indexOfObject:download];
        
        UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:index
                                                                                         inSection:0]];
        [cell.detailTextLabel setText:[self subtitleForDownload:download]];
        
        [cell setEditing:NO animated:YES];
    }
}
  • 问题

它的Demo演示还是有点问题。添加了一个实际可下载的任务,还是无法下载。

4. MCDownloadManager

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [[MCDownloadManager defaultInstance] removeWithURL:self.urls[indexPath.row]];
        [self.tableView reloadData];
    }
}
image.png
  • 问题

它这个删除还是有点问题: 删除文件后,receipt 的标记还是 MCDownloadStateCompleted 。它的作者也新建了一个基于NSOperation的框架MCDownloader取代它。

5. MCDownloader

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        MCDownloadReceipt *receipt = [[MCDownloader sharedDownloader] downloadReceiptForURLString:[self urls][indexPath.row]];
        [[MCDownloader sharedDownloader] remove:receipt completed:^{
            [self.tableView reloadData];
        }];
        
    }
}

6. TYDownloadManager

if (_downloadModel.state == TYDownloadStateReadying) {
        [manager cancleWithDownloadModel:_downloadModel];
        return;
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 拒绝被安排 温暖常在 感谢亲友 排除杂音 SJTU 一切都是最好的安排
    珍惜眼前始为真阅读 108评论 0 0
  • 妍发烧,淋巴结肿大,今天带她去东区儿童医院看病。 医生简单的检查后,需要进一步做彩超和血常规检测。 当妍知道要扎手...
    sunfeng0912阅读 533评论 0 11
  • 第14章回顾 “你沿着这条路一直走就会到圣云帝都,然后出城了向北就到卡诺森林了。” 少女指着这条通往都城的道路对男...
    陈瀛Neptune阅读 554评论 0 6