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

作者: 小码僧 | 来源:发表于2018-09-19 15:18 被阅读24次

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

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;
    }

相关文章

网友评论

    本文标题:iOS·下载管理第三方框架初步调研

    本文链接:https://www.haomeiwen.com/subject/ofeinftx.html