cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
We are making some updates so the Community might be down for a few hours on Monday the 11th of November. Apologies for the inconvenience and thank you for your patience. You can find out more 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: 

DBRpcTask response block not called.

DBRpcTask response block not called.

rayleyendecker
Explorer | Level 3

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 call is made to [client.filesRoutes createFolder:folderPath] (checking for another folder) and so forth recuresively until everything gets unwound.  The first call works (response block is called) but the second (recursive) call does not result in its response bock being called. For example, the  [client.filesRoutes createFolder:folderPath] call created the folder but the response block is never called.  I am updating previously written code that worked fine when DBRestClient callbacks were used.  Not sure if this has something to do with calling Dropbox methods from within a response block that has a response block itself. 

 

Thank you.

4 Replies 4

Greg-DB
Dropbox Staff
Can you share the code that reproduces this, so we can make sure we understand the issue? Thanks in advance!

rayleyendecker
Explorer | 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-DB
Dropbox Staff
(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.)

rayleyendecker
Explorer | 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

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    rayleyendecker Explorer | Level 3
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?