代码之家  ›  专栏  ›  技术社区  ›  Aleem

如何使Dropbox的下载任务失效

  •  0
  • Aleem  · 技术社区  · 5 年前

    我使用Pods集成了Dropbox “pod‘ObjectiveDropbox官方’” 我请求特定的下载文件,如以下代码

    DBUserClient *client = [DBClientsManager authorizedClient];
    [[[client.filesRoutes downloadData:imagePath]
     setResponseBlock:^(DBFILESFileMetadata *result, DBFILESDownloadError *routeError, DBRequestError *error, NSData *fileData) {
    
         if (result) {
             NSLog(@"File Downloaded")
             [[SingletonSDK sharedInstance] hideProgessHud];
         }
    
    }] setProgressBlock:^(int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) {
         if (!isCancelButtonAlreadyAppear) {
             [[SingletonSDK sharedInstance] showCancelButton:self];
             isCancelButtonAlreadyAppear = true;
         } }];
    

    下载页面上有“取消”按钮,所以当用户按“取消”时,应该取消。我确实喜欢通过以下方式获得共享的URLSession,然后失效,因为我在上没有找到任何取消下载或失效下载方法 Dropbox Documentation

    - (void)cancelButtonPressedProgressHud {
    [[SingletonSDK sharedInstance] hideProgessHud];
    NSURLSession * sharedURLSession = NSURLSession.sharedSession;
    [sharedURLSession invalidateAndCancel];
    }
    

    我也试过这个 gist category class 使所有URL下载会话无效,但不起作用。

    如果有人面对或知道如何停止从Dropbox下载的文件,请谅解。 事先谢谢。

    1 回复  |  直到 5 年前
        1
  •  1
  •   Greg    5 年前

    您可以使用 DBTask -cancel .例如,这看起来像:

    DBDownloadDataTask *req = [client.filesRoutes download...
    [req cancel];