Aleem
Aleem

Reputation: 3291

How to Invalidate downloading task of Dropbox

I integrated Dropbox using Pods "pod 'ObjectiveDropboxOfficial'" I requested for specific downloading file like following code

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

There is cancel button on downloading page, so when user press cancel it should cancel. I did like following to get shared urlsession and then invalidate because I didn't found any cancel downloading or invalidate downloading method on Dropbox Documentation

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

I also tried this gist category class to invalidate all url downloading session but didn't work.

Kindly if someone faced or have any idea how to stop file which is in downloading from dropbox. Thanks in Advance.

Upvotes: 0

Views: 89

Answers (1)

Greg
Greg

Reputation: 16940

You can cancel individual download tasks in the Dropbox API v2 Objective-C SDK using DBTask -cancel. For example, that would look like:

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

Upvotes: 1

Related Questions