筆者目前比較關(guān)注的點(diǎn)是第三方框架中,刪除指定下載任務(wù)的處理邏輯。
1.FGDownloader
移除任務(wù)示例
- (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 當(dāng)其他任務(wù)在下載的時(shí)候 移除會(huì)導(dǎo)致無法暫停
[[FGGDownloadManager shredManager] removeForUrl:model.url file:model.destinationPath];移除的時(shí)候下載隊(duì)列出問題了
2.HJDownloadManager
移除任務(wù)示例
- (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];
}];

- 問題
下載進(jìn)度的回調(diào)可能有BUG:可能是這個(gè)回調(diào)不準(zhǔn)_downloadModel.progressChanged。表現(xiàn)為:直到下載成功才直到下載了,下載中無法知道是否下載狀態(tài)。

3.TCBlobDownload
刪除任務(wù)示例
- (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演示還是有點(diǎn)問題。添加了一個(gè)實(shí)際可下載的任務(wù),還是無法下載。
4. MCDownloadManager
刪除任務(wù)示例
- (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
- 問題
它這個(gè)刪除還是有點(diǎn)問題: 刪除文件后,receipt 的標(biāo)記還是 MCDownloadStateCompleted 。它的作者也新建了一個(gè)基于NSOperation的框架MCDownloader取代它。
5. MCDownloader

移除任務(wù)示例
- (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];
}];
}
}

- 問題
無法下載HTTP的資源,會(huì)報(bào)錯(cuò),解決辦法可以是允許http連接。參考http://www.itdecent.cn/p/b4389e7346d2。
6. TYDownloadManager

移除下載任務(wù)
if (_downloadModel.state == TYDownloadStateReadying) {
[manager cancleWithDownloadModel:_downloadModel];
return;
}
