cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Re: [Obj-C v2] How to cancel requests?

[Obj-C v2] How to cancel requests?

philipkd
Collaborator | Level 8
Go to solution

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?

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

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

 

View solution in original post

2 Replies 2

Greg-DB
Dropbox Staff
Go to solution

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

 

philipkd
Collaborator | Level 8
Go to solution
Awesome, looks like it's working now. Not sure what I was doing wrong. Thanks!
Need more support?