iOS·下載管理第三方框架初步調(diào)研

筆者目前比較關(guān)注的點(diǎn)是第三方框架中,刪除指定下載任務(wù)的處理邏輯。

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 當(dāng)其他任務(wù)在下載的時(shí)候 移除會(huì)導(dǎo)致無法暫停
    [[FGGDownloadManager shredManager] removeForUrl:model.url file:model.destinationPath];移除的時(shí)候下載隊(duì)列出問題了

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

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演示還是有點(diǎn)問題。添加了一個(gè)實(shí)際可下載的任務(wù),還是無法下載。

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
  • 問題

它這個(gè)刪除還是有點(diǎn)問題: 刪除文件后,receipt 的標(biāo)記還是 MCDownloadStateCompleted 。它的作者也新建了一個(gè)基于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;
    }
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 拒絕被安排 溫暖常在 感謝親友 排除雜音 SJTU 一切都是最好的安排
    珍惜眼前始為真閱讀 111評(píng)論 0 0
  • 妍發(fā)燒,淋巴結(jié)腫大,今天帶她去東區(qū)兒童醫(yī)院看病。 醫(yī)生簡(jiǎn)單的檢查后,需要進(jìn)一步做彩超和血常規(guī)檢測(cè)。 當(dāng)妍知道要扎手...
    sunfeng0912閱讀 580評(píng)論 0 11
  • 第14章回顧 “你沿著這條路一直走就會(huì)到圣云帝都,然后出城了向北就到卡諾森林了?!?少女指著這條通往都城的道路對(duì)男...
    陳瀛Neptune閱讀 625評(píng)論 0 6

友情鏈接更多精彩內(nèi)容