iOS开发攻城狮的集散地iOS地图iOS直播视频

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

2018-09-19  本文已影响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];
        });
    });
}

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

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

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;
    }
上一篇 下一篇

猜你喜欢

热点阅读