One month down in 2025: How are your resolutions coming along? Check out how to get back on track here.
Forum Discussion
philipkd
8 years agoCollaborator | Level 8
[Obj-C v2] How to cancel requests?
If I follow the sample guidance, I do this:
[[client.filesRoutes ...] setResponseBlock:...]
But I'm not sure how to cancel the request.
I tried doing something like this:
DBTask *task = [client.filesRoutes ...]; [task setResponseBlock:...]
And then if I need to cancel, do [task cancel]
But then the task wouldn't execute.
Any ideas?
Calling cancel on the task object is the right way to cancel the request. I'm not sure what you mean when you say "the task wouldn't execute". That is the expected behavior once you call cancel.
Also, you can use setResponseBlock on the same line as where you retrieve the task object, in case that's the issue you're concerned about. For example:
DBTask *task = [[client.filesRoutes downloadData:remotePath] setResponseBlock:^(DBFILESFileMetadata *metadata, DBFILESDownloadError *downloadError, DBRequestError *error, NSData *fileData) { // handle result }];
BOOL shouldCancel = true; // to be determined by something in your app, e.g., the user hitting a "Cancel" button if (shouldCancel) { NSLog(@"Cancelling."); [task cancel]; }
- Greg-DB
Dropbox Staff
Calling cancel on the task object is the right way to cancel the request. I'm not sure what you mean when you say "the task wouldn't execute". That is the expected behavior once you call cancel.
Also, you can use setResponseBlock on the same line as where you retrieve the task object, in case that's the issue you're concerned about. For example:
DBTask *task = [[client.filesRoutes downloadData:remotePath] setResponseBlock:^(DBFILESFileMetadata *metadata, DBFILESDownloadError *downloadError, DBRequestError *error, NSData *fileData) { // handle result }];
BOOL shouldCancel = true; // to be determined by something in your app, e.g., the user hitting a "Cancel" button if (shouldCancel) { NSLog(@"Cancelling."); [task cancel]; }
- philipkdCollaborator | Level 8Awesome, looks like it's working now. Not sure what I was doing wrong. Thanks!
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,945 PostsLatest Activity: 7 hours ago
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!