Forum Discussion

rayleyendecker's avatar
rayleyendecker
Explorer | Level 3
8 years ago

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 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.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff
    Can you share the code that reproduces this, so we can make sure we understand the issue? Thanks in advance!
    • rayleyendecker's avatar
      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's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox 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.)

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,950 PostsLatest Activity: 14 hours ago
352 Following

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!