Your workflow is unique 👨💻 - tell us how you use Dropbox 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:
...
- 8 years ago
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 Community Moderator
8 years agoCalling 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];
}
- philipkd8 years agoCollaborator | Level 8Awesome, looks like it's working now. Not sure what I was doing wrong. Thanks!
About Dropbox API Support and Feedback
Get help with the Dropbox API from fellow developers and experts.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
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, Facebook or Instagram.
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!