Your workflow is unique 👨💻 - tell us how you use Dropbox here.
Forum Discussion
rayleyendecker
8 years agoExplorer | Level 3
DBRpcTask response block not called.
I have a method that calls [client.filesRoutes createFolder:folderPath]. In its response block a call is made to [client.filesRoutes search:parentPath query:filename]. In its response block another c...
Greg-DB
Dropbox Community Moderator
8 years agoCan you share the code that reproduces this, so we can make sure we understand the issue? Thanks in advance!
- rayleyendecker8 years agoExplorer | Level 3
Here is the code. I tried to make it as minimal as possible but I think the pattern is clear.
- (DocumentMetaData*) createFolder:(DocumentMetaData*)folderInfo { NSURL *folderURL = [folderInfo itemURL]; NSString *folderPath = [[folderURL path] stringByReplacingPercentEscapesUsingEncoding:UTF8Encoding]; DBUserClient *client = [self getDropboxClient]; [[client.filesRoutes createFolder:folderPath] setResponseBlock:^(DBFILESFolderMetadata *result, DBFILESCreateFolderError *routeError, DBRequestError *networkError) { if (result) { if ([delegate respondsToSelector:@selector(checkFolderCreated)]) { [delegate checkFolderCreated:YES]; } } else { LALog(@"%@\n%@\n", routeError, networkError); } }]; //Wait-loop for create folder request with the given timeout NSDate* giveUpDate = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_CREATE_FOLDER_IN_SECS]; while ( (self.currentRequestStatus == REQ_PROCESSING) && [giveUpDate timeIntervalSinceNow] > 0) { //Keep looping.. Run the current run for a millisec for the Network and UI async events to be taken care of NSDate *stopDate = [NSDate dateWithTimeIntervalSinceNow:0.001]; [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:stopDate]; } Delegate Class: - (void) checkFolderCreated:(BOOL)success withInfo:(NSDictionary *)infoPassedIn { DocumentController *docController = (DocumentController*)[infoPassedIn objectForKey:@"DocumentController"]; if (docController == nil) return; … [docController createFolder:docMetaData]; … // some condition to pop out. }Here the first call to createFolder successfully has its response block called. All additional calls execute the createFolder method (the folder is created) but the response block is not called.
The while loop is used to make the call synchronous in this case. This may be interfering with the response block being called back but not sure. Any ideas?
- Greg-DB8 years ago
Dropbox Community Moderator
(Apologies for the delay. It looks like there was an issue with the form, and your post wasn't showing up before.)
Yes, I think that while loop might cause this. The response block runs asynchonrously, and on the main thread:
https://github.com/dropbox/dropbox-sdk-obj-c#specify-api-call-response-queue
If I understand correctly, it sounds like you're blocking the main thread, so the response block may not get a chance to run.
I recommend refactoring that to eliminate that, or use another queue or sempahores, or whatever makes sense for your app.
(Also, one shortcut on the API side of things: if you're creating folders to contain files you'll later be uploading, you can actually skip the folder creation step entirely. When uploading files via the API, any parent folders in the destination path that don't already exist will be automatically created.)- rayleyendecker8 years agoExplorer | Level 3
You are correct. It was indeed a result of using the while loop to block and wait. Since the response block was running on the main thread along with my block and wait code my repsonse block would not run until the my wait loop timed out. I fixed it by adding a queueu to each call so the response block runs in a seperate thread. It all works now. Thank you so much for your reply. Have a greate day!
Thanks,
Ray
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!